function rl()
   local r = {}
   for word in io.read():gmatch("%S+") do
      table.insert(r, tonumber(word))
   end
   return r
end

function ru()
   return unpack(rl())
end

function pu(x, ...)
   if x then
      io.write(x, ' ')
      return pu(...)
   else
      io.write('\n')
   end
end

N = ru()

pu(math.fmod(1000000 - N, 1000))
