#include <bits/stdc++.h>
main()
{
 	long long int V;
	int br_nov=0;
	int br_cif=0;
	long long int max=-1,sred,min;
	scanf("%lld",&V);
	long long int V1=V;
	while(V1>0)
	{
		br_cif++;
		V1=V1/10;
	}

	while(br_cif>=0)
	{
		if((5*pow(10,br_cif))>max)
		{
			max=(5*pow(10,br_cif));
			if((2*pow(10,br_cif))>(1*pow(10,br_cif)))
			{
				sred=(2*pow(10,br_cif));
				min=(1*pow(10,br_cif));
			}
			else
			{
				sred=(1*pow(10,br_cif));
				min=(2*pow(10,br_cif));
			}		
		}	
		
		if((2*pow(10,br_cif))>max)
		{
			max=(2*pow(10,br_cif));
			if((5*pow(10,br_cif))>(1*pow(10,br_cif)))
			{
				sred=(5*pow(10,br_cif));
				min=(1*pow(10,br_cif));
			}
			else
			{
				sred=(1*pow(10,br_cif));
				min=(5*pow(10,br_cif));
			}		
		}
		
		if((1*pow(10,br_cif))>max)
		{
			max=(1*pow(10,br_cif));
			if((5*pow(10,br_cif))>(2*pow(10,br_cif)))
			{
				sred=(5*pow(10,br_cif));
				min=(2*pow(10,br_cif));
			}
			else
			{
				sred=(2*pow(10,br_cif));
				min=(5*pow(10,br_cif));
			}		
		}
		
		while(V>=0)
		{
			if(V-max>=0)
			{
				V=V-max;
				br_nov++;
			}
			else
				break;
		}
		
		while(V>=0)
		{
			if(V-sred>=0)
			{
				V=V-sred;
				br_nov++;
			}
			else
				break;
		}
		
		while(V>=0)
		{
			if(V-min>=0)
			{
				V=V-min;
				br_nov++;
			}
			else
				break;
		}
		max=-1,sred=0,min=0;
		br_cif--;
	}
	printf("%d",br_nov);
}