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

namespace ConsoleApp1
{
    class Program
    {
        static int brojcif(ulong skr)
        {
            int br = 0;
            while(skr>0)
            {
                skr /= 10;
                br++;
            }
            return br;
        }
        static void Main(string[] args)
        {
            ulong n = Convert.ToUInt64(Console.ReadLine());
            int brojnovcanica = 0;
            int br;
            while(n>0)
            {
                br = brojcif(n);
                int k = (int)((n / (ulong)Math.Pow(10, br - 1)) % (ulong)Math.Pow(10, br + 1));
                if (k >= 5)
                {
                    n -= (ulong)(5 * Math.Pow(10, br-1));
                    brojnovcanica++;
                }
                else if (k >= 2)
                {
                    n -= (ulong)(2 * Math.Pow(10, br-1));
                    brojnovcanica++;
                }
                else
                {
                    n -= (ulong)(Math.Pow(10, br-1));
                    brojnovcanica++;
                } 
            }
            Console.WriteLine(brojnovcanica);


        }
    }
}