#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    ll n;

    cin >> n;

    ll brc = (ll)(floor(log10(n)) + 1);
    brc--;
    brc = pow(10,brc);

    ll ar[3] = {5,2,1};

    ll res = 0;

    while(n > 0)
    {
        for(ll i = 0; i < 3;)
        {
            ll x = brc*ar[i];
            if(n >= x)
            {
                n-=x;
                res++;
            }
            else
            {
                i++;
            }
        }
        brc/= 10;
    }

    cout << res;
}