program isplata;
uses math;
var
  b: longint;
  t, z, i: shortint;
  v: qword;
  n: array [1..36] of qword;
begin
  read(v);

  t := 57;
  b := 0;
  z := 3;

  n[1] := 1;
  n[2] := 2;
  n[3] := 5;

  for i := 1 to 18 do begin
    n[i+z] := 10 ** i;
    n[i+1+z] := (10 ** i)*2;
    n[i+2+z] := (10 ** i)*5;
    z := z + 3;
  end;

  while v <> 0 do begin
    if n[t] <= v then begin
      v := v - n[t];
      b := b + 1;
    end
    else t := t - 1;
  end;
  
  write(b);
end.