c=[]
ans=[]
3.times do |i|
c[i]=gets.chomp.to_i
end

for i in 0..2
  if c[i]==0
     ans[i]="\n"
  else
    s1=(1000-c[i])/500
    r1=(1000-c[i])%500
    s2=r1/100
    r2=r1%100
    s3=r2/50
    r3=r2%50
    s4=r3/10
    r4=r3%10
    s5=r4/5
    r5=r4%5

    ans[i]=s1+s2+s3+s4+s5+r5
  end
end

puts ans