class Problem
  attr_accessor :a, :b, :c, :n, :m, :h, :w, :x, :y, :ans
  def initialize
    @n = gets.to_s.to_i
  end

  def solve
    puts calc == 0 ? 0 : 1000 - calc
  end

  def calc
    n % 1000
  end
end

pb = Problem.new
pb.solve