using System;

public class Program
{
    static int K(long n)
    {
        int k = -1;
        while (n > 0)
        {
            n /= 10;
            k++;
        }
        return k;
    }

    static int resi(long n)
    {
        int br = 0;
        int a = 1, b = 2, c = 5;
        long k = (long)Math.Pow(10, K(n));
        while (n > 0)
        {
            if (n >= c * k)
            {
                n -= c * k;
                br++;
            }
            while (n >= b * k)
            {
                n -= b * k;
                br++;
            }
            if (n >= a * k)
            {
                n -= a * k;
                br++;
            }
            if (n < a * k)
            {
                k /= 10;
            }
        }
        return br;
    }

    public static void Main(string[] args)
    {
        long n = long.Parse(Console.ReadLine());
        // 121412181214 prvo gledam zadnju cifru
        // 1 2 5 10 20 50 100 200 500 1000 2000 5000
        Console.WriteLine(resi(n));
    }
}