#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <vector>

int main() {
	int a, j = 0, u = 0, q = 0;
	std::vector<int> o(3);
	o[0] = 1;	o[1] = 2;	o[2] = 5;
	scanf_s("%d", &a);
	if (a >= 10) {
		for (int i = 3, j = 0; o[j] < a; i++, j++) {
			o.push_back(o[j] * 10);
			if (o.back() > a) { o.pop_back(); break; }
			u = o.size();
		}
		for (int i = 1; a != 0; i++) {
			a -= o[u - i];
			if (a >= o[u - i]) { a -= o[u - i]; q++; };
			if (a < 0) { a += o[u - i]; q--; };
			q++;
		}
	}
	else {
		int c[9] = { 1,1,2,2,1,2,2,3,3 };
		q = c[a-1];
	}
	std::cout << q;
	return 0;
}