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

namespace cvrsti_brojevi
{
    class Program
    {
        static void ilj (ref List<int>c, ref int[] p, ref int[] k, ref int a, ref int j, ref bool b)
        {
            bool[] h = new bool[10];
            bool[] h1 = new bool[10];
            for (int i=0; i<10; i++)
            {
                p[i] = 0;
                k[i] = 0;
                h[i] = true;
                h1[i] = true;
            }
            List<int> l = new List<int>();
            for (int i = 0; i < c.Count; i++)
            {
                if (!l.Contains(c[i]))
                {
                    l.Add(c[i]);
                    if (h[c[i]]) p[c[i]] = i;
                    h[c[i]] = false;
                }
                else
                {
                    l.Remove(c[i]);
                    if (h1[c[i]]) k[c[i]] = i;
                    h1[c[i]] = false;
                    if (i - p[c[i]] == 1) h1[c[i]] = true;
                }
                if (i > 0)
                {
                    if (c[i - 1] == c[i] && h1[c[i]]) h[c[i]] = true;
                }
            }
            int min = int.MaxValue;
            for (int i = 0; i < 10; i++)
            {
                if (k[i]-p[i]-1 > 0)
                {
                    if (k[i] - p[i]-1 < min)
                    {
                        min = k[i] - p[i] - 1;
                        j = i;
                    }
                    b = true;
                }
            }
        }
        static void Main(string[] args)
        {
            ulong n = ulong.Parse(Console.ReadLine());
            List<int> c = new List<int>();
            ulong n1 = n;
            while (n1 > 0)
            {
                c.Add((int)(n1 % 10));
                n1 = n1 / 10;
            }
            int[] p = new int[10];
            int[] k = new int[10];
            int a = 0;
            int j = 0;
            bool b = false;
            ilj(ref c, ref p, ref k, ref a, ref j, ref b);
            if (b)
            {
                for (int i = p[j] + 1; i < k[j]; i++)
                {
                    c[i] = j;
                    a++;
                }
            }
            bool m = true;
            while(m)
            {
                b = false;
                ilj(ref c, ref p, ref k, ref a, ref j, ref b);
                if (b)
                {
                    for (int i = p[j] + 1; i < k[j]; i++)
                    {
                        c[i] = j;
                        a++;
                    }
                }
                else m = false;
            }
            Console.WriteLine(a);
        }
    }
}