import std.stdio;
import std.conv;
import std.string;

void main() {
	int a;
	int [] c = [500, 100, 50, 10, 5, 1];
	int res = 0;
	a = to!int(chomp(readln()));
	a = 1000 - a;

	for(int i = 0; i < c.length; i++) {
		if(a >= c[i]) {
			res++;
			a -= c[i];
			i--;
		}
	}

	writeln(res);
}