using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
         
        static void Main(string[] args)
        {
            Int64 n = int.Parse(Console.ReadLine());
            Int64 s = 0;
            Int64 fk = 0;
            
            int k = 0;
            int l = 0;
            int stepen=10;
            int dz = 0;
            for (int i = 0; s < n; i++)
            {
                if (i == 0)
                {
                    s = 5;
                }
                else
                {
                    stepen = 10;
                    for(int g=1;g<i;g++)
                {
                    stepen*= stepen;
                }

                    s = 5 * stepen;
                    
                }

                dz = i;
            }
            int fl=k;
            while (n > s)
            {
                n -= s;
                k++;
            }

            if (fl != k)
            {
                for (int i = 0; s < n; i++)
                {
                    if (i == 0)
                    {
                        s = 5;
                    }
                    else
                    {
                        stepen = 10;
                        for (int g = 1; g < i; g++)
                        {
                            stepen *= stepen;
                        }

                        s = 5 * stepen;

                    }

                    dz = i;
                }
                while (n > s)
                {
                    n -= s;
                    k++;
                }
                s = 0;

                for (int m = 0; s < n; m++)
                {
                    if (m <= dz)
                    {


                        if (m == 0)
                        {

                            s = 2;
                        }
                        else
                        {
                            stepen = 10;
                            for (int g = 1; g < m; g++)
                            {
                                stepen *= stepen;
                            }

                            s = 2 * stepen;
                        }
                    }
                    else
                    {
                        fk = s;
                        s = n + 1;
                    }
                }
                while (n > fk)
                {
                    n -= fk;
                    k++;
                }
                s = 0;

                for (int c = 0; s < n; c++)
                {
                    if (c <= dz)
                    {
                        if (c == 0)
                        {
                            s = 1;
                        }
                        else
                        {
                            stepen = 10;
                            for (int g = 1; g < c; g++)
                            {
                                stepen *= stepen;
                            }

                            s = 1 * stepen;
                        }
                    }
                    else
                    {
                        fk = s;
                        s = n + 1;
                    }
                }
                while (n > fk)
                {
                    n -= fk;
                    k++;
                }
               
            }


            s = 0;
            
            for (int m = 0; s < n; m++)
            {
                if (m <= dz)
                {


                    if (m == 0)
                    {

                        s = 2;
                    }
                    else
                    {
                        stepen = 10;
                        for (int g = 1; g < m; g++)
                        {
                            stepen *= stepen;
                        }

                        s = 2 * stepen;
                    }
                }
                else
                {
                    fk = s;
                    s = n + 1;
                }
            }
            fl = k;
            while (n > fk)
            {
                n -= fk;
                k++;
            }
            if (fl != k)
            {
                s = 0;
                for (int i = 0; s < n; i++)
                {
                    if (i == 0)
                    {
                        s = 5;
                    }
                    else
                    {
                        stepen = 10;
                        for (int g = 1; g < i; g++)
                        {
                            stepen *= stepen;
                        }

                        s = 5 * stepen;

                    }

                    dz = i;
                }
                while (n > s)
                {
                    n -= s;
                    k++;
                }
                s = 0;

                for (int m = 0; s < n; m++)
                {
                    if (m <= dz)
                    {


                        if (m == 0)
                        {

                            s = 2;
                        }
                        else
                        {
                            stepen = 10;
                            for (int g = 1; g < m; g++)
                            {
                                stepen *= stepen;
                            }

                            s = 2 * stepen;
                        }
                    }
                    else
                    {
                        fk = s;
                        s = n + 1;
                    }
                }
                while (n > fk)
                {
                    n -= fk;
                    k++;
                }
                s = 0;

                for (int c = 0; s < n; c++)
                {
                    if (c <= dz)
                    {
                        if (c == 0)
                        {
                            s = 1;
                        }
                        else
                        {
                            stepen = 10;
                            for (int g = 1; g < c; g++)
                            {
                                stepen *= stepen;
                            }

                            s = 1 * stepen;
                        }
                    }
                    else
                    {
                        fk = s;
                        s = n + 1;
                    }
                }
                while (n > fk)
                {
                    n -= fk;
                    k++;
                }
                
            }
            s = 0;

            for (int c = 0; s < n; c++)
            {
                if (c <= dz)
                {
                    if (c == 0)
                    {
                        s = 1;
                    }
                    else
                    {
                        stepen = 10;
                        for (int g = 1; g < c; g++)
                        {
                            stepen *= stepen;
                        }

                        s = 1 * stepen;
                    }
                }else
                {
                    fk = s;
                    s = n + 1;
                }
            }
            fl = k;
            while (n > fk)
            {
                n -= fk;
                k++;
            }
            if (fl != k)
            {
                s = 0;
                for (int i = 0; s < n; i++)
                {
                    if (i == 0)
                    {
                        s = 5;
                    }
                    else
                    {
                        stepen = 10;
                        for (int g = 1; g < i; g++)
                        {
                            stepen *= stepen;
                        }

                        s = 5 * stepen;

                    }

                    dz = i;
                }
                while (n > s)
                {
                    n -= s;
                    k++;
                }
                s = 0;

                for (int m = 0; s < n; m++)
                {
                    if (m <= dz)
                    {


                        if (m == 0)
                        {

                            s = 2;
                        }
                        else
                        {
                            stepen = 10;
                            for (int g = 1; g < m; g++)
                            {
                                stepen *= stepen;
                            }

                            s = 2 * stepen;
                        }
                    }
                    else
                    {
                        fk = s;
                        s = n + 1;
                    }
                }
                while (n > fk)
                {
                    n -= fk;
                    k++;
                }
                s = 0;

                for (int c = 0; s < n; c++)
                {
                    if (c <= dz)
                    {
                        if (c == 0)
                        {
                            s = 1;
                        }
                        else
                        {
                            stepen = 10;
                            for (int g = 1; g < c; g++)
                            {
                                stepen *= stepen;
                            }

                            s = 1 * stepen;
                        }
                    }
                    else
                    {
                        fk = s;
                        s = n + 1;
                    }
                }
                while (n > fk)
                {
                    n -= fk;
                    k++;
                }
                
            }
            s = 0;
            Console.WriteLine(k);




        }
    }
}