a, b = (int(n) for n in input().split(' ')) if a > b: print(2*10**9 - b - 1) else: print(b-2)