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