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