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

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            double n = double.Parse(Console.ReadLine());
            int d = 1, k = 5;
            double ostatak = n; 
            double i = n / 10;
            int nov = 0;
            if (i <= 9) d = 1;
            else if (i <= 9999) d = 2;
            else d = 5;
            while (d > 0)
            {
                double w = Math.Pow(10, d);
                while (k > 0 && n != 0)
                {
                    if (n % (k * w) == n)
                    {
                        if (k == 5) k = 2;
                        else k--;
                    }
                    else
                        while (n % (k * w) != n)
                        {
                            n = n - k * w;
                            nov++;
                        }
                }
                if (d == 5) d = 2;
                else d--;
            }
            ostatak = n;
            k = 5;
            while (k > 0 && ostatak != 0)
            {
                if (ostatak % k == ostatak)
                {
                    if (k == 5) k = 2;
                    else k--;
                }
                else
                    while (ostatak % k != ostatak)
                    {
                        ostatak = ostatak - k;
                        nov++;
                    }
            }
            Console.WriteLine(nov);
        }
    }
}