#include <iostream>
#include <vector>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	unsigned long long x,br=0;
	vector<unsigned long long> v;
	unsigned long long i,a=1,b=2,c=5;
	cin>>x;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	while(c<x){
		a*=10;
		b*=10;
		c*=10;
		v.push_back(a);
		v.push_back(b);
		v.push_back(c);
	}
	i=v.size()-1;
	while(x>1){
		while(x>=v[i]){
			x-=v[i];
			br++;
		//	cout<<x<<" "<<v[i]<<endl;
		}
		i--;
		if(x==1){
			br++;
			break;
		}
	}
	cout<<br;
	return 0;
}