A, B, S = map(int, input().split()) if abs(A - S) <= abs(B - S) or S == 1: print(abs(A - S) + S) elif A < B: if A == 0: print(abs(B - S) + abs(A - S) + A + 1) else: print(abs(B - S) + abs(A - S) + A) else: print(min(abs(B - S) + (A - S) + A, abs(B - S) + S - 1 + A))