#include <cstdio>
#include <algorithm>
#include <cmath>



using namespace std;

long long broj1( long long x)
{
    unsigned long long y = 1;
    while(x>y)
    {
        y*=10;
    }
    if(x==y) return y;
    else y/=10;
    if(x>=5*y) return 5*y;
    else if(x>=2*y) return 2*y;
    else return y;
}


int main()
{
    long long a;
    scanf("%lld", &a);
    int m = 1;
    while(a>0)
    {
        a-=broj1(a);
        m++;
    }
    printf("%d", m-1);








    return 0;
}