#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<ll> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

int main()
{
    ll x;
    cin >> x;

    vi a;
    ll t = 1;
    for (int i = 0; i <= 18; ++i){
        a.push_back(t);
        a.push_back(2ll * t);
        a.push_back(5ll * t);
        t *= 10ll;
    }

    sort(a.rbegin(), a.rend());
    int n = a.size();

    ll sol = 0ll;
    for (int i = 0; i < n; ++i){
        if (x < a[i]) continue;

        sol += x / a[i];
        x %= a[i];
    }

    cout << sol << '\n';
}