A, B = map(int, input().split()) print([B-2, 2*10**9-B-11][A > B])