a, b, s = map(int, raw_input().split()) if a == -1: a = 0 if abs(s-a) <= abs(s-b): print abs(s-a)+s else: print abs(s-b) + max(abs(s-a)+a+(a==0), s-1 + abs(a-1) + 1)