# yukicoder No.333 門松列を数え上げ

A, B = map(int, input().split())
M = 2 * (10 ** 9)

print(M - B - 1 if A > B else B - 2)