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