using System;

namespace kv1_z4
{
    class Program
    {
        static void ucvrst(int[] a, int n, ref bool p)
        {
            int c;
            p = false;
            for (int i = 0; i < n; i++)
            {
                for (int j = 1; j < n; j++)
                {
                    if (a[j] == a[i])
                    {
                        c = a[j];
                        for (int r = i + 1; r < j; r++) if (a[r] != c) 
                        {
                            a[r - 1] = a[r]; p = true;
                        }
                    }
                }
            }
        }
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int[] a = new int[s.Length];
            for (int i = 0; i < s.Length; i++) a[i] = (s[i] - 48);
            int brp = 0, c;
            bool p = true;
            while (p)
            {
                ucvrst(a, s.Length, ref p); 
            }
            for (int i = 0; i < s.Length; i++) if (s[i] - 48 != a[i]) brp++;
            Console.WriteLine(brp);
        }
    }
}