#include <bits/stdc++.h>

using namespace std;

int main ()
{
	long long v;
	cin >> v;

	int br=0;
	while(v)
	{
		long long k=1;
		while(k <= v)
		{
			k*=10;
		}
		k/=10;
		if(k*5 <= v) k*=5;
		else if(k*2 <= v) k*=2;
		v-=k;
		br++;
	}
	cout << br << endl;
}