#include <iostream>
using namespace std;
unsigned int duzina(long long unsigned int v)
{
	unsigned int brojac=0;
	while(v!=0)
	{
		v/=10;
		brojac++;
	}
	return brojac;
}
long long unsigned int power(int x,int y)
{
	long long unsigned int z=1;
	for(unsigned int i=0;i<y;i++)
		z*=x;
	return z;
}
int main()
{
	long long unsigned int v,tmp;
	cin >> v;
	int duz=duzina(v)-1,brojac=0;
	while(v!=0)
	{
		if(duz==0)
			tmp=1;
		else if(duz==1)
			tmp=10;
		else
			tmp=power(10,duz);
		if(v>=tmp*5)
		{
			v-=tmp*5;
			brojac++;
		}
		else if(v>=tmp*2)
		{
			v-=tmp*2;
			brojac++;
		}
		else if(v>=tmp)
		{
			v-=tmp;
			brojac++;
		}
		else
			duz--;
	}
	cout << brojac;
}