#include <bits/stdc++.h>

using namespace std;
deque<int>deq;
int main()
{
    long long int a,b;
    scanf("%lld",&a);
    b=a;

    long long int sol=0;
    while(a>0)
    {
        deq.push_front(a%10);
        a/=10;
    }
    int m=deq.size();

    while(!deq.empty())
    {
    int k=deq[0];
    if(k>5){deq.pop_front();deq.push_front(k-5);sol++;}
    if(k==5 || k==2 || k==1) {deq.pop_front();sol++;}
    if(k==3 || k==4) {deq.pop_front();deq.push_front(k-2);sol++;}
    if(k==0){break;}
    }
    printf("%d",sol);
            return 0;
}