a, b = [int(x) for x in input().split()] res = abs(b - a) - 1 if a < b: res += a - 1 else: res += 2 * 10**9 - a print(res)