A, B = [int(i) for i in input().split()] if A < B: print(B - 2) else: print(2000000000 - B - 1)