a,b = map(int,input().split()) if a > b: print(2000000000-b-1) else: print(b-2)