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