import java.util.Scanner;
public class P5585 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int balance = 1000 - sc.nextInt(), answer = 0;
int[] coin = { 500, 100, 50, 10, 5, 1 };
for (int ele : coin) {
answer += balance / ele;
balance %= ele;
}
System.out.println(answer);
sc.close();
}
}