# No.333 門松列を数え上げ a, b = [int(i) for i in input().split()] if a < b: print((a - 1) + (b - a - 1)) elif a == 2000000000: print(2000000000 - a - 1) else: print((2000000000 - a - 1) + (a - b))