#include <iostream>
#include <string>
#include <algorithm>
#include <limits>
#include <iomanip>
#include <cmath>

using namespace std;

typedef numeric_limits<streamsize> ignore_t;

int main() 
{
	int V{};
	int d[]{ 1, 2, 5 };
	int k{};

	scanf_s("%d", &V);

	do 
	{
		if (pow(10, k) >= V) 
		{
			break;
		}
		++k;
	} while (1);

	int* novcanice = new int[3 * k];
	
	for (int i{}; i < k; ++i)
	{
		int j{};
		for (static int ii{}; ii < 3*(i+1); ++ii) 
		{
			novcanice[ii] = d[j++] * pow(10, i);
		}
	}

	sort(novcanice, novcanice + (3*k), greater<int>());

	int br_novcanica{};

	while (V != 0) 
	{
		for (int i{}; i < 3 * k && V != 0; ++i) 
		{
			if (novcanice[i] <= V) 
			{
				++br_novcanica;
				V = V - novcanice[i];
				break;
			}
		}
	}

	cout << "\n" << br_novcanica;

	delete[] novcanice;

	cin.clear();
	cin.ignore(ignore_t::max(), '\n');
	cin.get();

	return 0;
}