defmodule Main do
  def main do
    IO.gets("")
    |> String.trim()
    |> String.to_integer()
    |> get_mod()
    |> IO.puts()
  end
 
  def get_mod(m) do
    d = rem(m, 1000)
    cond do
      d > 0 -> 1000 - d
      true -> 0
    end
  end
end