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