n, k = io.read("*n", "*n") if(k == 0 or n < k) then print(0) elseif(n + 1 == k * 2) then print(n - 1) else print(n - 2) end