#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n;
string x;
ll dp[6005];
ll mini[6005][11];
ll dp2[6005];
ll pref[100005][12];

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> x;
    n = x.length();
    ff(j,0,9)pref[0][0] = 0;
    ff(i,0,n - 1){
        int tr = x[i] - '0';
        ff(j,0,9)pref[i + 1][j] += pref[i][j];
        ff(j,0,9){
            if(j == tr)continue;
            pref[i + 1][j]++;
        }
    }
    ff(j,0,5000)dp[j] = 1e9;
    ff(j,0,5000){
        ff(k,0,9)mini[j][k] = 1e9;
    }
    ff(k,0,9)mini[0][k] = 0;
    ff(i,1,n){

        ff(j,1,(1<<10) - 1){
            dp[j] = 1e9;
            ff(k,0,9){
                if(!(j&(1<<k)))continue;
                dp[j] = min(dp[j], mini[j^(1<<k)][k] + pref[i][k]);
            }
        }
        ff(j,1,(1<<10) - 1){
            ff(k,0,9){
                mini[j][k] = min(mini[j][k], dp[j] - pref[i][k]);
            }
        }
    }
    ll ans = 1e9;
    ff(j,1,(1<<10) - 1)ans = min(ans, dp[j]);
    cout << ans << "\n";
    return 0;
}