N = gets.chomp.to_i

1.upto(10) do |i|
    payment = 1000 * i
    if payment >= N then
        puts (payment - N).to_s
        exit
    end
end

# n = N[-3, 3].to_i
# if n == 0 then
#     puts 0
# else
#     puts (1000 - n)
# end
