#include <iostream>
#include <math.h>

using namespace std;

int main()
{
long v,v1,k=0,br=0;
cin>>v;
v1=v;
while (v1>0)
 {v1=v1/10;
  k++;}
  
k=k-1;
while (v!=0)
 {
  while ((5*pow(10,k))<=v)
   {v=v-5*pow(10,k);
    br++;}
  while ((2*pow(10,k))<=v)
   {v=v-2*pow(10,k);
    br++;}
  while ((pow(10,k))<=v)
   {v=v-pow(10,k);
    br++;}
  k--; }
  cout<<br;

}