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());
                                                int k = 0;
                                                            int br = 0;
                                                                        ulong a = v;
                                                                                    while (a>=10)
                                                                                                {
                                                                                                                a /= 10;
                                                                                                                                k++;
                                                                                                                                            }
                                                                                                                                                        for (int i=k; i>-1; i--)
                                                                                                                                                                    {
                                                                                                                                                                                    while (v >= Math.Pow(10, i))
                                                                                                                                                                                                    {
                                                                                                                                                                                                                        if (v >= 5 * Math.Pow(10, i))
                                                                                                                                                                                                                                            {
                                                                                                                                                                                                                                                                    v -= 5 * (ulong)Math.Pow(10, i);
                                                                                                                                                                                                                                                                                            br++;
                                                                                                                                                                                                                                                                                                                }
                                                                                                                                                                                                                                                                                                                                    else if (v >= 2 * Math.Pow(10, i))
                                                                                                                                                                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                                                                                                                                                v -= 2 * (ulong)Math.Pow(10, i);
                                                                                                                                                                                                                                                                                                                                                                                                        br++;
                                                                                                                                                                                                                                                                                                                                                                                                                            }
                                                                                                                                                                                                                                                                                                                                                                                                                                                else
                                                                                                                                                                                                                                                                                                                                                                                                                                                                    {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            v -= (ulong)Math.Pow(10, i);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    br++;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Console.WriteLine(br);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            }