#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int br = 0;

int Generisi( int V )
{
	int eksponent = 0;
	int k;

	for ( int g = 0; g < 18; g++ )
	{
		if ( g%3 == 0 )
		{
			k = pow( 10, eksponent );
		}
		else if ( g%3 == 0 )
		{
			k = pow( 10, eksponent );
		}
		else
		{
			k = pow( 10, eksponent );
			eksponent++;
		}
		if ( k > V )
		{
			return k;
		}
	}
}

int main()
{
	int V;
	int k;

	while ( V )
	{
		k = Generisi(V);
		V -= k;
		br++;
	}
	
	cout << br;
	return 0;
}