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

int n;
string s;
int dp[2][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){
            dp[0][bitMask][j] = 100001;
            dp[1][bitMask][j] = 100001;
        }
    }

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

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

    int res = 100001;
    for(int i = 1; i < n; ++i){
        int newId = i % 2;
        int oldId = (i + 1) % 2;

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

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

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

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

    cout << res << "\n";

    return 0;
}

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