program isplata;
uses math;
var
  b: longint;
  t, z, i: shortint;
  v, p: qword;
  n: array [1..57] 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;

  p := v;

  while v <> p do begin
    if n[t] <= p then begin
      p := p - n[t];
      b := b + 1;
      
    end
    else t := t - 1;
    
  end;





  write(b);
end.