#include <stdio.h>
#include <stdlib.h>

unsigned long long int brojac(unsigned long long int a)
{
    unsigned long long int br=0;
    while(a!=0)
    {
        a=a/10;
        br++;
    }
    return br;
}

unsigned long long int stepen(unsigned long long int a, unsigned long long int stepen)
{
    if(stepen==0)
        return 1;
    unsigned long long int p=a;
    int i;
    for(i=1;i<stepen;i++)
        a=a*p;
    return a;
}

int main()
{
    unsigned long long int v;
    scanf("%llu",&v);
    unsigned long long int br=brojac(v);
    unsigned long long int broj=0;

    while(v!=0)
    {
        if(5*stepen(10,br-1)<=v)
        {
            v=v-5*stepen(10,br-1);
            broj++;
        }
        else if(2*stepen(10,br-1)<=v)
        {
            v=v-2*stepen(10,br-1);
            broj++;
        }
        else if(stepen(10,br-1)<=v)
        {
            v=v-stepen(10,br-1);
            broj++;
        }
        br=brojac(v);
    }
    printf("%llu",broj);
}