a, b = [ int(v) for v in input().split() ] if a < b: print(b - 2) else: print(2000000000 - b - 1)