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