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