#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];
            brNovc+=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);
    }
    cout<<pohlepnoIzbroj(novcanice, novcanice.size(), v)<<"\n";
    return 0;
}