A, B, S = map(int, input().split()) min_total = float('inf') if S == 1: # Down button case: B cannot move, so A comes total_down = abs(A - 1) + 1 min_total = min(min_total, total_down) # Up button case: check if A is closer or equal a_dist = abs(A - 1) b_dist = abs(B - 1) if a_dist <= b_dist: total_up = a_dist + 1 min_total = min(min_total, total_up) else: # For other floors, check if A is closer or equal when pressing down button a_dist = abs(A - S) b_dist = abs(B - S) if a_dist <= b_dist: total = a_dist + S min_total = total print(min_total)