p00444 Change
problem

Taro often shop at JOI general stores. At JOI general stores, there are enough coins of 500 yen, 100 yen, 50 yen, 10 yen, 5 yen, and 1 yen, and we always pay the change so that the number of coins is the smallest. Create a program to find the number of coins included in the change you receive when Taro goes shopping at the JOI general store and puts out one 1000 yen bill at the cash register.

For example, in the case of input example 1, 4 must be output as shown in the figure below.

<image>



input

The input consists of multiple datasets. Each dataset consists of one line, and only one amount (an integer of 1 or more and less than 1000) paid by Taro is written. The input data ends with one zero line.

The number of datasets does not exceed 5.

output

Output the number of coins included in the change for each dataset on one line.

Examples

Input

380
1
0


Output

4
15


Input

None


Output

None
```python
while True:
    x = int(input())
    if x == 0:
        break
    else:
        x=1000-x
        a=x//500
        b=(x-500*a)//100
        c=(x-(500*a+100*b))//50
        d=(x-(500*a+100*b+50*c))//10
        e=(x-(500*a+100*b+50*c+10*d))//5
        f=(x-(500*a+100*b+50*c+10*d+5*e))//1
        print(a+b+c+d+e+f)

```