while n = gets
if n == nil
  break 
  end
ch = n.chomp.to_i
x = 1000 - ch
cnt = 0

if 500 <= x
  cnt += 1
  x -= 500
  end
while 100 <= x 
  cnt += 1
  x -= 100
  end
while 50 <= x 
  cnt += 1
  x -= 50
  end
while 10 <= x 
  cnt += 1
  x -= 10
  end
while 5 <= x 
  cnt += 1
  x -= 5
  end
while 1 <= x 
  cnt += 1
  x -= 1
  end
puts cnt