MAX = 2*10**9 a, b = map(int, raw_input().split()) if a < b: print b - 2 else: print MAX - b - 1