P = int(input())
change = 1000 - P
coins = 0
coins += change // 500
change = change % 500
coins += change // 100
change = change % 100
coins += change // 50
change = change % 50
coins += change // 10
change = change % 10
coins += change // 5
change = change % 5
coins += change // 1
change = change % 1
print(coins)

438714ad260f61df7ac5db53b7c92fea7683c111
<mask token>

<mask token>
coins += change // 500
<mask token>
coins += change // 100
<mask token>
coins += change // 50
<mask token>
coins += change // 10
<mask token>
coins += change // 5
<mask token>
coins += change // 1
<mask token>
print(coins)

P = int(input())
change = 1000 - P
coins = 0
coins += change // 500
change = change % 500
coins += change // 100
change = change % 100
coins += change // 50
change = change % 50
coins += change // 10
change = change % 10
coins += change // 5
change = change % 5
coins += change // 1
change = change % 1
print(coins)
