Learning to Stop Overthinking at Test Time