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