Program isplata;
var v:longint;x:integer;
begin
readln(v); 
x:=0;
while v>=1 do begin
if v>=500000 then begin
v:=v-500000;
x:=x+1;
end
else begin
if v>=200000 then begin
v:=v-200000;
x:=x+1;
end
else begin
if v>=100000 then begin
v:=v-100000;
x:=x+1;
end
else begin
if v>=50000 then begin
v:=v-50000;
x:=x+1;
end
else begin
if v>=20000 then begin 
v:=v-20000;
x:=x+1;
end
else begin
if v>=10000 then begin
v:=v-1000;
x:=x+1;
end
else begin
if v>=5000 then begin
v:=v-5000;
x:=x+1;
end
else begin
if v>=2000 then begin
v:=v-2000;
x:=x+1;
end
else begin
if v>=1000 then begin
v:=v-1000;
x:=x+1;
end
else begin
if v>=500 then begin
v:=v-500;
x:=x+1;
end
else begin
if v>=200 then begin 
v:=v-200;
x:=x+1;
end
else begin
if v>= 100 then begin 
v:=v-100;
x:=x+1;
end
else begin
if v>=50 then begin
v:=v-50;
x:=x+1;
end
else begin
if v>=20 then begin
v:=v-20;
x:=x+1;
end
else begin
if v>=10 then begin 
v:=v-10;
x:=x+1;
end
else begin 
if v>=5 then begin
v:=v-5;
x:=x+1;
end
else begin
if v>=2 then begin 
v:=v-2;
x:=x+1;
end
else begin
if v>=1 then begin 
v:=v-1;
x:=x+1;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
writeln(x);
end.