-module('Main').
-export([main/1]).

main(_) ->
    {ok, [N]} = io:fread("", "~d"),
    case N rem 1000 == 0 of
    	true ->
        	Ans = 0;
        false ->
        	Ans = 1000 - (N rem 1000)
    end,
    io:format("~p~n", [Ans]),
    halt().