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

namespace Contest
{
    partial class Program
    {
        static void Main(string[] args)
        {
            ABC155_E();
        }

        static void ABC155_A()
        {
            var abc = ReadIntN();
            var A = abc[0];
            var B = abc[1];
            var C = abc[2];
            if (A == B && B == C) { Console.WriteLine("No");return; }
            if (A == B || A == C || B == C) { Console.WriteLine("Yes");return; }
            Console.WriteLine("No");
        }
        static void ABC155_B()
        {
            var N = ReadInt();
            var A = ReadIntN();
            for(int i = 0; i < N; ++i)
            { var a = A[i];
                if (a % 2 == 0 && (a % 3 > 0 && a % 5 > 0)) { Console.WriteLine("DENIED");return; }
            }
            Console.WriteLine("APPROVED");
        }
        static void ABC155_C()
        {
            var N = ReadInt();
            Dictionary<string, int> dict = new Dictionary<string, int>();
            for (int i = 0; i < N; ++i)
            {
                var s = Console.ReadLine();
                if (!dict.ContainsKey(s)) { dict.Add(s, 0); }
                dict[s] += 1;
            }
            var max = dict.Values.Max();
            var keys = dict.Where(x => x.Value == max).Select(x => x.Key).ToList();
            keys.Sort(StringComparer.OrdinalIgnoreCase);
            foreach (var s in keys)
            {
                Console.WriteLine(s);
            }
        }
        static void ABC155_D()
        {
            var nk = ReadLongN();
            var A = ReadLongN();
            var N = nk[0];
            var K = nk[1];
            A = A.OrderBy(x => x).ToArray();
            var A2 = A.Select(x => x * x).ToArray();

            var nbNeg = A.Count(x => x < 0);
            var nbZero = A.Count(x => x == 0);

            // xより小さいペアの個数を返す
            Func<long, long> lessThan = x => {
                long count = 0;

                //Negativeに対して尺取り法
                if (x >= 0) //反転させたやつを使えばループの場合わけいらないよね
                {
                    long right = N;
                    for (int left = 0; left < nbNeg; ++left)
                    {
                        while (right > 0 && A[left] * A[right - 1] < x)
                        {
                            right--;
                        }
                        count += N - right;
                    }
                }
                else
                {
                    long right = 0;
                    for (int left = 0; left < nbNeg; ++left)
                    {
                        while (right < N && A[left] * A[right] >= x)
                        {
                            right++;
                        }
                        count += N - right;
                    }
                }

                //Zero
                count += x > 0 ? nbZero * N : 0;

                //Positiveに対して尺取り法
                if (x >= 0)
                {
                    long right = N;
                    for (int left = nbNeg + nbZero; left < N; ++left)
                    {
                        while (right > 0 && A[left] * A[right - 1] >= x)
                        {
                            right--;
                        }
                        count += right;
                    }
                }
                else
                {
                    long right = 0;
                    for (int left = nbNeg + nbZero; left < N; ++left)
                    {
                        while (right < N && A[left] * A[right] < x)
                        {
                            right++;
                        }
                        count += right;
                    }
                }

                //(i,j)に制約をつけないN^2に対する個数が求まったので
                //対角成分の個数を引いて半分にし、i<jの個数にする
                return (count - A2.Count(v => v < x)) / 2;
            };

            //二分探索
            long max = 1000000000000000001;
            long min = -max;
            while (min + 1 < max)
            {
                long mid = (min + max) / 2;
                var count = lessThan(mid);
                if (count < K)
                {
                    min = mid;
                }
                else
                {
                    max = mid;
                }
            }
            Console.WriteLine(min);

        }
        static void ABC155_E()
        {
            var str = Console.ReadLine();
            int useMajor = 99, useMinor = 0;
            foreach(var c in str)
            {
                var d = ((int)c) - 48;
                var nextMajor = Math.Min(useMajor + 9, useMinor + 11) - d;
                var nextMinor = Math.Min(useMajor, useMinor) + d;
                useMajor = nextMajor;
                useMinor = nextMinor;
            }
            Console.WriteLine(Math.Min(useMajor, useMinor));
        }
        static void ABC155_F()
        {

        }

        static string ReadStr()
        {
            return Console.ReadLine();
        }
        static string[] ReadStrN()
        {
            return Console.ReadLine().Split(' ');
        }
        static int ReadInt()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
        static int[] ReadIntN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
        }
        static long ReadLong()
        {
            return Convert.ToInt64(Console.ReadLine());
        }
        static long[] ReadLongN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
        }
        static Tuple<long, long>[]  ReadTupleLong(int n)
        {
            List<Tuple<long, long>> list = new List<Tuple<long, long>>();
            for (int i = 0; i < n; ++i)
            {
                var ab = ReadLongN();
                list.Add(new Tuple<long, long>(ab[0], ab[1]));
            }
            return list.ToArray();
        }
    }
}


Measured memory_bytes: 14816