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