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

namespace Prvi_zadatak
{
    class Program
    {
        static int PrvaCifra(long V)
        {
            int i;
            for (i=0; V>10; i++)
            {
                V /= 10;
            }
            return i;
        }
        static void Main(string[] args)
        {
            long V;
            V = Convert.ToInt64(Console.ReadLine());
            int n, brojNovcanica = 0,temp;
            for ( brojNovcanica=0 ; V != 0 ; brojNovcanica++)
            {
                n = PrvaCifra(V);
                temp = (int)(V / Math.Pow(10, n));
                if (temp >= 5)
                {
                    V -= (long)(5 * Math.Pow(10, n));
                }
                else if (temp >= 2)
                {
                    V -= (long)(2 * Math.Pow(10, n));
                }
                else
                {
                    V -= (long)(Math.Pow(10, n));
                }
            }
            Console.WriteLine(brojNovcanica);
        }
    }
}