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