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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            long input = long.Parse(Console.ReadLine());
            long[] niz = new long[57];
            int count = 0;
            int gen = 0;
            for (int i = 0; i < 19; i++)
            {
                long p = 1 * (long)Math.Pow(10, i);
                niz[gen] = p;
                gen++;
                long d = 2 * (long)Math.Pow(10, i);
                niz[gen] = d;
                gen++;
                long t = 5 * (long)Math.Pow(10, i);
                niz[gen] = t;
                gen++;
            }
            for (int i = niz.Length - 1; i >= 0; i--)
            {
                if (niz[i] <= input)
                {
                    int br = 0;
                    for (int j = 1; j < 20; j++)
                    {
                        if ((j * niz[i]) <= input)
                            br++;
                        else break;
                    }
                    input -= (br * niz[i]);
                    count += br;
                }
            }
            Console.WriteLine(count);

        }
    }
}