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