inp = map(int, raw_input().split()) A = inp[0] B = inp[1] if A < B: C = B - 2 elif B < A: C = 2e9 - B - 1 print int(C)