A, B, S = map(int, input().split()) if S == 1: # Only A can be called moves = abs(A - 1) + 1 else: a_dist = abs(A - S) b_dist = abs(B - S) if b_dist < a_dist: # B is called, then go to 1st floor and call A moves = b_dist + S + abs(A - 1) else: # A is called moves = a_dist + S print(moves)