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) if a == 0: step += abs(a - 1) + s else: step += min(abs(a - 1) + s, abs(s - a) + a) print(step)