program Project1;
var
  v,k,q,x,y,i:integer;
begin
  readln(v);
  q:=v;
  k:=0;
  y:=1;
  x:=0;
  while q>0 do
  begin
  q:=q div 10;
  k:=k+1;
  end;
  k:=k-1;
  for i:=1 to k do
  y:=y*10;
    while v>0 do
  begin
  while (5*y<=v) do
  begin
  v:=v-5*y;
  x:=x+1
  end;
  while (2*y<=v) do
  begin
  v:=v-2*y;
  x:=x+1
  end;
  while (y<=v) do
  begin
  v:=v-y;
  x:=x+1;
  end;
  end;
  writeln(x);
  readln;
end.