#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(0);

    cin.tie(0);


    long long v;

    cin >> v;

    long long brCifre = (long long)(floor(log10(v)) + 1);

    brCifre--;

    long long stepen = pow(10,brCifre );

    long long brP = 0;

    while(v)
    {
        if(v >= stepen*5)
        {
            v-=stepen*5;
            brP++;


        }
        else if (v >= stepen*2)
        {
            v-=stepen*2;

            brP++;


        }
        else if ( v >= stepen)
        {
            v -= stepen;

            brP++;

        }
        else
        {
            stepen /= 10;
        }

    }

    cout << brP;



    return 0;
}