#include <bits/stdc++.h>

int brojcifara(unsigned long long int n)
{   
    int br = 0;
    while(n > 0)
    {
        n = n / 10;
        br++;
    }
    return br;
}

int brojnov(unsigned long long int v, &brn)
{   
    if(v == 0)
        return brn;
    int br1 = brojcifara(v);
    while(brojcifara(v) >= br1)
    {
        if(v >= pow(10,br1 - 1) * 5)
        {
            v = v - pow(10,br1 - 1) * 5;
            brn++;
        }
        else if(v >= pow(10,br1 - 1) * 2)
        {
            v = v - pow(10,br1 - 1) * 2;
            brn++;
        }
        else
        {
            v = v - pow(10,br1 - 1);
            brn++;
        }
    }
    brojnov(v , brn);
    
}

using namespace std;

int main()
{   int brn = 0;
    unsigned long long int v;
    cin >> v;
    cout << brojnov(v , brn);
    return 0;
}