#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int brojcifara(long long unsigned int a)
{
    int cifre = 0;

    while(a != 0)
    {
        a = a / 10;
        cifre++;
    }

    return cifre;
}
long long unsigned int stepen (int x,int y)
{
    long long unsigned int a=1;
    int i;
    for(i=0; i<y; i++)
    {
        a=a*x;
    }
    return a;
}
int main()
{
    long long unsigned int suma;
    cin>>suma;
    int brojac=0;
    long long unsigned int pomocna;
    int duzina;
    duzina=brojcifara(suma);
    while(suma!=0)
    {
        if(duzina==0)
            pomocna=1;
        else
            pomocna=stepen(10,duzina);
        if(suma>=pomocna*5)
        {
            suma=suma-(pomocna*5);
            brojac+=1;
        }
        else if(suma>=pomocna*2)
        {
            suma=suma-(pomocna*2);
            brojac+=1;
        }
        else if(suma>=pomocna)
        {
            suma=suma-pomocna;
            brojac+=1;
        }
        else
            duzina--;
    }
    cout<<brojac;

    return 0;
}