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

namespace ConsoleApplication26
{
    class Program
    {
        static int bc(ulong x)
        {
            int b = 0;
            while (x > 0)
            {
                x = x / 10;
                b++;
            }
            return b;
        }

        static void Main(string[] args)
        {
            ulong v,c;
            int b,n=0;
            
            v = ulong.Parse(Console.ReadLine());
            while(v>0)
            {
                b = bc(v);
               // Console.WriteLine(b);
                c = v / (ulong)(Math.Pow(10, (b - 1)));
                if (c >= 5)
                {
                    v = v - (ulong)(5*Math.Pow(10, (b - 1)));
                    n++;
                }
                else if (c >= 2)
                {
                    v = v - (ulong)(2*Math.Pow(10, (b - 1)));
                    n++;
                }
                else
                {
                    v = v - (ulong)(Math.Pow(10, (b - 1)));
                    n++;
                }
            }
            Console.WriteLine(n);
        }
    }
}