#include <iostream>
#include <cmath>

using namespace std;

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

int main() {
	long max, pom, v, novc = 0, k;
	cin>>v;
	k = v;
	while(v > 0) {
		max = katarina(v, pom);
		v -= max;
		novc++;
		if(v == 0) novc++;
	}
	if (k % 10 == 9) novc++;
	cout<<--novc;
}