#include <stdio.h>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
    int d;
    scanf("%d",&d);
    vector<long long int> a;
    while(d)
    {
        a.push_back(d%10);
        d=d/10;
    } 
    long long int br=0;
    for(vector <long long int> :: iterator it=a.begin();it!=a.end();it++)
        while(*it)
            if(*it>=5)
            {
                *it-=5;
                br++;
            }
            else if(*it>=2)
                {
                    *it-=2;
                    br++;
                    
                }
            else { *it-=1; br++;}
    
    printf("%lld",br);
    return 0;
}