#include <iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);

    long long int s,t,i,j,k,res=0;
    cin>>s;

    t=1;
    for(i=1;i<=18;i++) t=t*10;

    for(i=18;i>=0;i--)
    {
        //cout<<"ttt "<<t*5<<endl;
       if(s>=t*5) {res++; s-=t*5; } // cout<<"sss "<<s<<endl;}
       if(s>=t*2) {res++; s-=t*2; } //cout<<"sss "<<s<<endl;}
       if(s>=t*2) {res++; s-=t*2;}  //cout<<"sss "<<s<<endl;}
       if(s>=t) {res++; s-=t;}   //cout<<"sss "<<s<<endl;}
       if(s>=t) {res++; s-=t;}  //cout<<"sss "<<s<<endl;}

       t/=10;
    }
    cout <<res;

    return 0;
}