A, B = list(map(int, input().split())) if A < B: count = (A - 1) + (B - (A + 1)) else: count = (A - (B + 1)) + (2000000000 - A) print(count)