A, B = map(int, input().split()) if B > A: case1 = A - 1 else: case1 = 2000000000 - A case2 = max(A, B) - min(A, B) - 1 print(case1 + case2)