a, b = map(int, input().split()) if a > b: c = a - b + 2 * 10**9 - a - 1 elif a < b: c = a - 1 print(c)