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

int n;
string s;
int dpOld[1030][15];
int dpNew[1030][15];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> s;

    n = s.size();

    for(int bitMask = 0; bitMask < (1 << 10); ++bitMask){
        for(int j = 0; j <= 10; ++j){
            dpOld[bitMask][j] = 100001;
            dpNew[bitMask][j] = 100001;
        }
    }

    for(int i = 0; i <= 9; ++i){
        dpOld[1 << i][i] = ((s[0] - '0') == i ? 0 : 1);
        dpOld[1 << i][10] = dpOld[1 << i][i];
    }

    if(n == 1){cout << 0 << "\n"; return 0;}

    int res = 100001;
    for(int i = 1; i < n; ++i){
        for(int bitMask = 1; bitMask < (1 << 10); ++bitMask){
            if(__builtin_popcount(bitMask) > (i + 1)){continue;}

            dpNew[bitMask][10] = 100001;
            for(int j = 0; j < 10; ++j){
                if((bitMask & (1 << j)) == 0){continue;}

                int add = ((s[i] - '0') == j ? 0 : 1);
                dpNew[bitMask][j] = min(dpOld[bitMask][j], dpOld[bitMask - (1 << j)][10]) + add;
                dpNew[bitMask][10] = min(dpNew[bitMask][10], dpNew[bitMask][j]);
            }

            if(i == n - 1){res = min(res, dpNew[bitMask][10]);}
        }

        for(int bitMask = 1; bitMask < (1 << 10); ++bitMask){
            if(__builtin_popcount(bitMask) > (i + 1)){continue;}

            for(int j = 0; j < 10; ++j){
                if((bitMask & (1 << j)) == 0){continue;}

                dpOld[bitMask][j] = dpNew[bitMask][j];
            }

            dpOld[bitMask][10] = dpNew[bitMask][10];
        }
    }

    cout << res << "\n";

    return 0;
}

//cout << i << " ,dpNew[" << bitMask << "][" << j << "] = " << dpNew[bitMask][j] << "\n";
//cout << i << " ,dpNew[" << bitMask << "][" << 10 << "] = " << dpNew[bitMask][10] << "\n";