#include<iostream>
#include<cmath>

using namespace std;
int f(long long n)
{
	if(n==0) return 0;
    return 1+f(n/10);
}
int main()
{
	int k,br=0;
    long long n,s;
	cin>>n;
	while(n!=0)
	{
		k=f(n)-1;
		s=pow(10,k);
		if(n-5*s>=0)
		{
			br++;
		    n=n-5*s;
		}
		else if(n-2*s>=0)
		{
			br++;
			n=n-2*s;
			//cout<<"b"<<n<<endl;
		}
		else	
		{
			br++;
			n=n-s;
			//cout<<"c"<<n<<endl;
		}
	}
	cout<<br;
}