#include<iostream>
#include<sstream> 
#include<cmath>
int countDigit(long long n) 
{ 
    if (n == 0) 
        return 0; 
    return 1 + countDigit(n / 10); 
} 
using namespace std;
main()
{
	long long V;
	scanf("%lli",&V);
	int brojCifara=countDigit(V);
	int n;
	if(V>=5*(long long)pow(10,brojCifara-1))
		n=brojCifara*3+1;
	else if(V>=2*(long long)pow(10,brojCifara-1) && V<5*(long long)pow(10,brojCifara-1))
		n=brojCifara*3-0;
	else if(V>=1*(long long)pow(10,brojCifara-1) && V<2*(long long)pow(10,brojCifara-1))
		n=brojCifara*3-1;
	long long novcici[n];
	int i,j=0;
	for(i=1;i-1<n;i++)
	{
		if(i%3==1)
				novcici[i-1]=(long long)pow(10,j);
		else if(i%3==2)
				novcici[i-1]=2*(long long)pow(10,j);
		else if(i%3==0)
			{
				novcici[i-1]=5*(long long)pow(10,j);
				j++;
			}
	}
	int brojac=0;
	i=0;
	while(V>0)
	{
		if(novcici[i]>V)
		{
			V=V-novcici[i-1];
			brojac++;
			i=0;
		}
		else
		{
			i++;
		}
	}
	printf("%d",brojac);
}