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