A, B = map(int, input().split()) print(2 * 10**9 - B - 1 if A > B else B - 2)