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