#include <iostream>
#include <cmath>

using namespace std;

int katarina(int k, int p) {
	for(int i = 0; i < 19; i++) {
		if(k >= (int)pow(10,i)) p = pow(10,i);
		else break;
		if(k >= (int)pow(10,i) * 2) p = pow(10,i) * 2;
		else break;
		if(k >= (int)pow(10,i) * 5) p = pow(10,i) * 5;
		else break;
	}
	return p;
}

int main() {
	int max, pom, v, novc = 0;
	cin>>v;
	while(v >= 0) {
		max = katarina(v, pom);
		v -= max;
		novc++;
	}
	cout<<--novc;
}