a, b, s = map(int, input().split()) step = 0 if s == 1 or abs(s - a) <= abs(s - b): # A → goal step += abs(s - a) + s else: # B → A → goal step += abs(s - b) + min(abs(s - a) + a, abs(a - 1) + s) print(step)