A, B = map(int, input().split()) if A < B: print(B - 2) elif A == B: print(0) else: print(2*10**9 - B - 1)