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