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