#include <bits/stdc++.h>
using namespace std;

const int ALPHABET_SIZE = 10;
const int N = 10005;
int dp[N][1025][ALPHABET_SIZE]; //dp[i][bitmask][lastDig]
//moguca je memorijska optimizacija, da skines N iz dp-a posto koristis samo i-1
int a[N];
int n;

const int INF = 99999999;

void setDefs(){
    for(int i = 0; i < n; ++i){
        for(int mask = 0; mask < (1 << ALPHABET_SIZE); ++mask){
            for(int j = 0; j < ALPHABET_SIZE; ++j){
                dp[i][mask][j] = INF;
            }
        }
    }
}

int main()
{
    {
        string str;
        cin >> str;
        n = str.size();
        for(int i = 0; i < n; ++i){
            a[i] = str[i] - '0';
        }
    }

    setDefs();

    for(int i = 0; i < ALPHABET_SIZE; ++i){
        dp[0][(1 << i)][i] = (i != a[0]);
    }

    for(int i = 1; i < n; ++i){
        for(int mask = 1; mask < (1 << ALPHABET_SIZE); ++mask){ //this is the mask for i-1, il create a new mask for me.
            for(int j = 0; j < ALPHABET_SIZE; ++j){
                int bit = (1 << j);
                if(bit & mask){ //if j is in mask
                    dp[i][mask][j] = min(dp[i][mask][j], dp[i-1][mask][j] + (j != a[i]));
                }else{//if j is not in mask
                    for(int k = 0; k < ALPHABET_SIZE; ++k){
                        if(k == j)
                            continue;
                        dp[i][mask | bit][j] = min(dp[i][mask | bit][j], dp[i-1][mask][k] + (j != a[i])); ///k will be some values which are not in mask; this is not possible; hopefully dp in that case is INT_MAX
                    }
                }
            }
        }
    }

    int res = INT_MAX;
    for(int mask = 1; mask < (1 << ALPHABET_SIZE); ++mask){
        for(int j = 0; j < ALPHABET_SIZE; ++j){
            res = min(res, dp[n - 1][mask][j]);
        }
    }

    cout << res << "\n";
    return 0;
}

///10! = 3.628.800 = 3 * 10^6
///max range intersect = 10 * 10 = 100