defmodule Main do
  def main do
	[n, k] = IO.read(:line)
      |> String.trim()
      |> String.split()
      |> Enum.map(&String.to_integer/1)
      ans = if n >= k do
    	rem(n, k)
      else
        1
      end
	IO.puts ans
  end
end
