using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            double x;
            int[] cifra = new int[3];
            double y;
            x = Convert.ToDouble(Console.ReadLine());
            
            int j;
            int br = 0;
            double desetka = Math.Pow(10, 18);
            cifra[0] = 5;
            cifra[1] = 2;
            cifra[2] = 1;
            
            while(x!=0)
            {
                desetka /= 10;
                for (j = 0; j < 3; j++)
                {
                    y = cifra[j] * desetka;
                    if (x >= y){
                        br++;
                        j--;
                        x -= y;
                        
                    }
                }
            }

            Console.WriteLine("{0}", br);
        }
    }
}