a, b = map(int, input().split()) ans = 0 if a < b: ans = a - 1 + (b - (a + 1)) elif a > b: ans = 2000000000 - a + (a - (b + 1)) print(ans)