program zad1;
uses math;
var a,i,j,k,l,rez:longint;
d:array[1..3] of longint;

function pow10(a:longint):longint;
var i,c:integer;
  begin
    c:=1;
    if a=0 then c:= 1
      else
        begin
          c:=1;
          for i:=1 to a do
            c:=c*10;
        end;
      pow10:= c;
  end;

begin
  d[1]:=5;
  d[2]:=2;
  d[3]:=1;
  rez:=0;
  read(a);

  while a<>0 do
    begin
      for i:=round(log10(a)) downto 0 do
      for j:=1 to 3 do
        begin
          if (pow10(i)*d[j]) <= a then
            begin
              while a>=(pow10(i) * d[j]) do
                begin
                  a:=a-(pow10(i) * d[j]);
                  rez:=rez+1;
                end;
            end;
        end;
    end;

  write(rez);
end.