Set E as the expected time to be in jail. Now there is three cases:

1 (1/3 probability): 0 years

2 (1/3 probability): 1 year, then you will have to do the same thing again, so in average 1 + E

3 (1/3 probability): 3 years, then you will have to do the same thing again, so in average 3 + E

To add it up, E = (1/3)*0 + (1/3)*(1+E) + (1/3)*(3+E). Now this is a regular linear equation.