#!/usr/bin/ruby                                                                                                                                   
# -*- coding: utf-8 -*-                                                                                                                           

change = 1000 - gets.to_i

res = 0
coins = [500, 100, 50, 10, 5, 1]
coins.each {|x|
  res += change / x
  change %= x
}
puts res