Martingales and the distribution of the time to ruin