i = gets.strip.to_i
r = case i.size
  when 1..3
    1000 - i
  when 4..Float::INFINITY
    _i = i.to_s.scan(/\d+\K\d{3}$/)[0].to_i
    _r = case _i
      when 0
        0
      else
        1000 - _i
      end
  when 0
    0
  end
puts r