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

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong v = ulong.Parse(Console.ReadLine());
            ulong v1 = v;
            int k = 0;
            while (v1>9)
            {
                v1 = v1 / 10;
                k++;
            }
            int b = 0;
            for (int i=k; i>=0; i--)
            {
                while (v >= Math.Pow(10, i))
                {
                    if (v >= 5 * Math.Pow(10, i)) v = v - 5 * (ulong)Math.Pow(10, i);
                    else if (v >= 2 * Math.Pow(10, i)) v = v - 2 * (ulong)Math.Pow(10, i);
                    else v = v - (ulong)Math.Pow(10, i);
                    b++;
                }
            }
            Console.WriteLine(b);
        }
    }
}