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

using namespace std;

int main()
{
    int v,k,i,j,pom,ost,kol,novcanice,brojcifre,actcifre;
    vector<int>  cifre;

    brojcifre=1;
    cin>>v;
    kol=v/10;
    
    ost=v%10;
    
    cifre.push_back(ost);
    while(kol!=0)
    {
        ost=kol%10;
        brojcifre++;
        cifre.push_back(ost);
        kol=kol/10;
    }
    

    novcanice=0;
    for(j=brojcifre;j>0;j--)
    {
        actcifre=cifre[j-1];
        while(actcifre!=0)
        {
            if(actcifre>=5)
            {
                v=v-int(5*pow(10,j));
                
                novcanice++;
                actcifre=actcifre-5;
            }
            else if(actcifre>=2)
            {
                v=v-int(2*pow(10,j));
                
                novcanice++;
                actcifre=actcifre-2;
            }
            else
            {
                v=v-int(pow(10,j));
                
                novcanice++;
                actcifre=actcifre-1;
            }
        }
    }

    cout<<novcanice;

    return 0;
}