#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long n;
    cin>>n;
    long long bc = (long long)(floor(log10(n)) + 1);
    long long bc10=pow(10,bc-1);
    long long s=0;
    while(n>0)
    {
        if(n>=5*bc10)
        {
            n-=5*bc10;
            s++;
        }
        else if(n>=2*bc10)
        {
            n-=2*bc10;
            s++;
        }
        else if(n>=bc10)
        {
            n-=bc10;
            s++;
        }
        else bc10/=10;
    }
    cout<<s;
}