import scala.io.StdIn.readInt

object Main {
  def main(args:Array[String]) = {
    var cnt = 0
    var n = 0
    while( { n = 1000-readInt; n} != 1000) {
      cnt = 0
      while(n>=500) { n -=500; cnt += 1 }
      while(n>=100) { n -=100; cnt += 1 }
      while(n>=50) { n -=50; cnt += 1 }
      while(n>=10) { n -=10; cnt += 1 }
      while(n>=5) { n -=5; cnt += 1 }
      while(n>=1) { n -=1; cnt += 1 }
      println(cnt)
    }
  }
}