def main(): A, B = map(int, input().split()) if A < B: ans = B - 2 else: ans = 2000000000 - B - 1 print(ans) main()