Min = 1 Max = 2 * 10**9 A, B = map(int, input().split()) if A < B: print(B - Min - 1) else: print(Max - B - 1)