#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;

ll pohlepnoIzbroj(vector<ll> v, ll n, ll zbir)
{
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    ll brojac[n]={0}, brNovc=0;
    for(ll i=0; i<n; ++i)
    {
        if(v[i]<=zbir)
        {
            brojac[i]=zbir/v[i];
            brNov+=brojac[i];
            zbir-=(brojac[i]*v[i]);
        }
    }

    return brNovc;
}
int main()
{
    ios::sync_with_stdio(false);
    ll v;
    cin>>v;

    vector<ll> novcanice;
    for(ll i=1; i<=10000; i*=10)
    {
        novcanice.push_back(i);
        novcanice.push_back(2*i);
        novcanice.push_back(5*i);
    }
    //sort(novcanice.begin(), novcanice.end());
    /*for(ll i=0; i<novcanice.size(); ++i)
    {
        cout<<novcanice[i]<<"\n";
    }*/
    //izbroj(novcanice, novcanice.size(), v, 0, 0);
    //cout<<izbrojac(novcanice, novcanice.size(), v)<<"\n";
    cout<<pohlepi(novcanice, novcanice.size(), v)<<"\n";
    return 0;
}