#include <iostream>
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int n=s.length();
    char c[n];
    for(int i=0;i<sizeof(c);i++)
    {
        c[i]=s[i];
    }
    int input[n];
    for(int i=0;i<n;i++)
    {
      input[i]=c[i]-48;
    }
    int isExistNum [10];
    int countNum[10] ;
    int lastMent[10] ;
    for(int i=0;i<10;i++)
    {
        isExistNum[i]=0;
        countNum[i]=0;
        lastMent[i]=0;
    }
    int result = 0;

            for (int i = 0; i < n; i++)
            {
                if (isExistNum[input[i]] == 1)
                {
                    int counter = 1, j, mini, start = 0, stop = 0, pos = 0,pp=0;

                    for (j = i; j < n; j++)
                    {
                        if (input[j] != input[j - 1])
                        {
                            if (j == i)
                                continue;
                            break;
                        }
                        else
                        {
                            if (j == i)
                            pp=1;
                            counter++;
                        }
                    }
                    if (pp == 0 )
                    {
                        if (counter < i - lastMent[input[i]] - 1)
                        {
                            pos = 3;
                            mini = counter;
                            start = i;
                            stop = i + counter;
                        }
                        else
                        {
                            pos = 2;
                            mini = i - lastMent[input[i]] - 1;
                            start = lastMent[input[i]] + 1;
                            stop = i;
                        }
                        if (mini > countNum[input[i]])
                        {
                            pos = 1;
                            mini = countNum[input[i]];
                            start = lastMent[input[i]] - countNum[input[i]] + 1;
                            stop = lastMent[input[i]] + 1;
                        }

                        for (int k = start; k < stop; k++)
                        {
                            result++;
                            switch (pos)
                            {
                                case 1:
                                    input[k] = input[lastMent[i] + 1];
                                    break;
                                case 2:
                                    isExistNum[input[k]] = 0;
                                    input[k] = input[i];
                                    break;
                                case 3:
                                    input[k] = input[i - 1];
                                    break;
                            }
                        }
                    }
                    switch (pos)
                    {
                        case 1:
                            countNum[lastMent[i] + 1] += stop - start;
                            break;
                        case 2:
                            countNum[input[i]] += counter + stop - start;
                            break;
                        case 3:
                            countNum[input[i]] = countNum[input[i - 1]] + counter;
                            break;
                        default:
                            countNum[input[i]] = counter;
                            break;
                    }
                    if (j - 1 < n)
                        i = j - 1;
                    else
                        i = n - 1;
                }
                else
                {
                    isExistNum[input[i]] = 1;
                    countNum[input[i]] = 1;
                }

                lastMent[input[i]] = i;
            }

            cout << result;
    return 0;
}