#include <bits/stdc++.h>
using namespace std;
long long v,res=0,niz[250],pr=2e18,x=60;

int main () {
    cin>>v;
    niz[1]=1;
    niz[2]=2;
    niz[3]=5;
    for (int i=4;i<=40;i++){
        niz[i]=niz[i-3]*10;
    }

    while (v!=0){


        for (int i=1;i<=40;i++){
                if (niz[i]>v)break;

           //    cout<<"niz "<<niz[i]<<endl;

            if (pr>v/niz[i]){
                pr=v/niz[i];
                x=niz[i];
            }

  //  cout<<"v/niz "<<v/niz[i]<<endl;


 //  cout<<"pr "<<pr<<endl;
//cout<<endl;

        }



     //   cout<<"nasao "<<pr<<endl;

        v-=x*pr;

        res+=pr;

         pr=2e18;

     //   cout<<"v "<<v<<endl;

   }


//cout<<"v kraj "<<v<<endl;

cout<<res<<endl;


return 0;
}