using System;

namespace Isplata
{
    class Program
    {
        static int brCifara(Int64 n)
        {
            int br = -1;
            while (n > 0)
            {
                n /= 10;
                br++;
            }
            return br;
        }
        static Int64 powuint(int a, int b)
        {
            while (b != 0)
            {
                a *= 10;
                b--;
            }
            return a;
        }
        static void Main(string[] args)
        {
            Int64 n = int.Parse(Console.ReadLine());
            int nov1 = 1, nov2 = 2, nov3 = 5, br = 0;
            Int64 a1, a2, a3;
            Int64 min = -1;
            while (n > 0)
            {
                a1 = (nov1 * (powuint(1, brCifara(n))));
                a2 = (nov2 * (powuint(1, brCifara(n))));
                a3 = (nov3 * (powuint(1, brCifara(n))));
                if (a1 > min && n - a1 >= 0)
                {
                    min = a1;
                }
                if (a2 > min && n - a2 >= 0)
                {
                    min = a2;
                }
                if (a3 > min && n - a3 >= 0)
                {
                    min = a3;
                }
                n -= min;
                min = 0;
                br++;
            }
            Console.WriteLine(br);
        }
    }
}