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