using System;

namespace ConsoleApp10
{
    class Program
    {
        static void Main(string[] args)
        {
            int V = int.Parse(Console.ReadLine());
            int br = 2;
            int[] A = new int[54];
            A[0] = 1;
            A[1] = 2;
            A[2] = 5;
            for(int k = 1; A[br-2] * 10 <= V; k++)
            {
                int m = 1;
                
                int j = k;
                while (j > 0)
                {
                    
                    m *= 10;
                    j--;
                }
               
                br++;
                A[br] = 1 * m;
                br++;
                A[br] = 2 * m;
                br++;
                A[br] = 5 * m;
                
            }
            
            int s = 0;

            for (int j = 0; V > 0; j++)
            {
                if (V < A[br])

                { br -= 1; }
                else
                {
                    int u = A[br];
                    V -= u;
                    s += 1;
                }
            }
            Console.WriteLine(s);


        }
    }
}