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