太郎君はよくJOI雑貨店で買い物をする． JOI雑貨店には硬貨は500円，100円，50円，10円，5円，1円が十分な数だけあり，いつも最も枚数が少なくなるようなおつりの支払い方をする．太郎君がJOI雑貨店で買い物をしてレジで1000円札を1枚出した時，もらうおつりに含まれる硬貨の枚数を求めるプログラムを作成せよ．  例えば入力例1の場合は下の図に示すように，4を出力しなければならない．  
taro_spend = []
spend_num = 0

for i in range(5):
    taro_spend.append(int(input()))
    if taro_spend[i] == 0:
        taro_spend.pop()
        break
    spend_num += 1

changes = [1000 - taro_spend[i] for i in range(spend_num)]
print(changes)
for change in changes:
    change_coin = 0

    if change >= 500:
        change -= 500
        change_coin += 1

    if change >= 100:
        while change >= 100:
            change -= 100
            change_coin += 1
            
    if change >= 50:
        change -= 50
        change_coin += 1
        
    if change >= 10:
        while change >= 10:
            change -= 10
            change_coin += 1

    if change >= 5:
        change -= 5
        change_coin += 1

    if change >= 1:
        while change >= 1:
            change -= 1
            change_coin += 1

    print(change_coin)
taro_spend = []
spend_num = 0

for i in range(5):
    taro_spend.append(int(input()))
    if taro_spend[i] == 0:
        taro_spend.pop()
        break
    spend_num += 1

changes = [1000 - taro_spend[i] for i in range(spend_num)]

for change in changes:
    change_coin = 0

    if change >= 500:
        change -= 500
        change_coin += 1

    if change >= 100:
        while change >= 100:
            change -= 100
            change_coin += 1
            
    if change >= 50:
        change -= 50
        change_coin += 1
        
    if change >= 10:
        while change >= 10:
            change -= 10
            change_coin += 1

    if change >= 5:
        change -= 5
        change_coin += 1

    if change >= 1:
        while change >= 1:
            change -= 1
            change_coin += 1

    print(change_coin)