#include <iostream>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll izbrojac(vector<ll> v, ll n, ll suma)
{
    if(suma==0)
        return 0;
    ll potrebno = INT_MAX;
    for(ll i=0; i<n; ++i)
    {
        //cout<<"i: "<<i<<"\n";
        if(v[i]<=suma)
        {
            ll podproblem = izbrojac(v, n, suma-v[i]);
            if(podproblem < suma)
                potrebno = podproblem + 1;
            //cout<<potrebno<<"\n";
        }
    }
    return potrebno;
}
int main()
{
    ios::sync_with_stdio(false);
    ll v;
    cin>>v;

    vector<ll> novcanice;
    for(ll i=1; i<=100; i*=10)
    {
        novcanice.push_back(i);
        novcanice.push_back(2*i);
        novcanice.push_back(5*i);
    }
    cout<<izbrojac(novcanice, novcanice.size(), v)<<"\n";
    return 0;
}