using System;

    class Program
    {
        static void Main(string[] args)
        {
            int d = 5, k = 0, br=0, br1 = 0, p=1;
            Int64 V = Int64.Parse(Console.ReadLine());
            Int64 V1 = V;
            while (V1>0)
            {
                V1 /= 10;
                br++;
            }
                for (k = br - 1; k >= 0; k--)
                {
                p = 1;
                while (p == 1)
                {
                    while ((d * (Int64)Math.Pow(10, k)) <= V)
                    {
                        br1++;
                        V -= (d * (Int64)Math.Pow(10, k));
                    }
                    if (d == 1)
                    {
                        d = 5;
                        p = 0;
                    }
                    else if (d == 2)
                        d = 1;
                    else
                        d = 2;
                }
                }
            Console.WriteLine(br1);
        }
    }