a, b, s = map(int, input().split()) if abs(s - a) <= abs(s - b): print(abs(s - a) + s) elif s == 1: print(a) else: ans = abs(s - b) if 1 <= a <= s: ans += s elif a == 0: ans += s + 1 else: ans += min(s + abs(a - 1), abs(a - s) + a) print(ans)