print((function (n, k) if k==0 or k>n then return 0 end return n-(bit.band(n,1)==1 and bit.rshift(n,1)+1==k and 1 or 2) end)(io.stdin:read("*n"), io.stdin:read("*n")))