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