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