A, B = list(map(int, input().split())) Nmax = 2000000000 if B == max(A, B): print(B - 2) else: print(Nmax - B - 1)