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