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