let n = read_int ();;

let amount n = let rec iter result m = 
                        if m > result then iter (result+1000) m
                        else -(m - result)
                      in iter 1000 n;;

Printf.printf "%d\n" (amount n);;