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