# No.333 門松列を数え上げ a, b = [int(i) for i in input().split()] if a < b: print(b - 2) else: print(2000000000 - b - 1)