using System;

namespace verseny1
{
    class Program
    {
        static void Main(string[] args)
        {
            string inp = Console.ReadLine();
            byte n = 0;
            //elso kar meghat
            {
                if ((inp[0] == '9') | (inp[0] == '8') | (inp[0] == '7') | (inp[0] == '6') | (inp[0] == '5'))
                {
                    n = Convert.ToByte(inp.Length * 3);
                }
                else if ((inp[0] == '4') | (inp[0] == '3') | (inp[0] == '2'))
                {
                    n = Convert.ToByte((inp.Length * 3) - 1);
                }
                else
                {
                    n = Convert.ToByte((inp.Length * 3) - 2);
                }
            }
            
            //long[] mon = new long[n];
            long V = Int64.Parse(inp);

            byte count = 0;
            //for (int i = 0; i < n; i++)
            while(V >= 0)
            {
                long exp = Convert.ToInt64(Math.Pow(10, inp.Length - 1));
                
                if (V - Convert.ToInt64(5 * exp) >= 0)
                {
                    count++;
                    V -= Convert.ToInt64(5 * exp);
                }
                             
                if (V - Convert.ToInt64(2 * exp) >= 0)
                {
                    count++;
                    V -=  Convert.ToInt64(2 * exp);
                }
                if (V - Convert.ToInt64(2 * exp) >= 0)
                {
                    count++;
                    V -= Convert.ToInt64(2 * exp);
                }

                if (V - Convert.ToInt64(1 * exp) >= 0)
                {
                    count++;
                    V -= Convert.ToInt64(1 * exp);
                }
                inp = V.ToString();
            }


            Console.WriteLine(count);



        }
    }
}