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