a,b = map(int,input().split()) if a < b: print(b - 2) else: print(2 * 10 ** 9 - b - 1)