#include <iostream>
int pd(long long b, int br)
{
	if (b > 0)
	{
		pd(b / 10, br + 1);
	}
	else
		return br;
}

int main()
{
	long long a;
	std::cin >> a;
	int n, k = 0;
	n = pd(a, 0);
	for (int i = n - 1; i > -1; i--)
	{
		if (a >= 5 * pow(10, i))
		{
			a = a - 5 * pow(10, i);
			k++;
			i++;
		}
		else
			if (a >= 2 * pow(10, i))
			{
				a = a - 2 * pow(10, i);
				k++;
				i++;
			}
				else
				if (a >= 1 * pow(10, i))
				{
					a = a - 1 * pow(10, i);
					k++;
					i++;
				}
		if (a <= 0)
			break;
	}
	//std::cout << a<<"<a";
	std::cout << k;
}