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

int gde[10];
int sled[100005][10];
int a[100005];
int dp[100005][1024];
short u[1024];

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

    string s;
    cin >> s;
    int n = s.size();
    for(int i=n-1; i>=0; i--){
        a[i] = s[i] - '0';
        for(int x=0; x<9; x++) sled[i][x] = gde[x];
        gde[a[i]] = i;
    }
    int res = 0;
    const int B = 10;
    for(int i=0; i<n; i++) u[i] = i;
    for(int i=0; i<n-1; i++){
        int sve = (1<<B)-1;
        sve ^= (1<<a[i]);
        for(int dmask=sve; ; dmask=(dmask-1)&sve){
            int mask = dmask | (1<<a[i]);
            dp[i][mask] = max(dp[i][mask], 1);
            res = max(res, dp[i][mask]);
            dp[sled[i][a[i]]][mask] = max(dp[sled[i][a[i]]][mask], dp[i][mask]+1);
            int komp = ((1<<B)-1) ^ mask;
            while(komp){
                int x = komp & -komp;
                dp[sled[i][u[x]]][mask|x] = max(dp[sled[i][u[x]]][mask|x], dp[i][mask]+1);
                komp -= x;
            }
            if(dmask == 0) break;
        }
    }
    cout << n-res;
    return 0;
}