#include <iostream>

using namespace std;

int main()
{
    unsigned long long int n, i, k = 0, x;

    cin >> n;

    x = n;

    while(x)
    {
        i = 1;
        while(i <= x/10)
        {
            i *= 10;
        }
        if((5*i) <= x)
        {
            x -= 5*i;
            //cout << k << " 1 " << 5*i << endl;
        }
        else if((2*i) <= x)
        {
            x -= 2*i;
            //cout << k << " 2 " << 2*i << endl;
        }
        else
        {
            x -= i;
            //cout << k << " 3 " << i << endl;
        }
        ++k;
    }

    cout << k << endl;
    return 0;
}