a, b = io.read("*n", "*n") if(a < b) then print(b - 2) else print(2000000000 - b - 1) end