#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xx first
#define yy second
#define srt(a) sort(a.begin(),a.end());
#define srtg(a,ll) sort(a.begin(),a.end(),greater<ll>())
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define up(a,x) upper_bound(a.begin(),a.end(),x)
#define fnd(a,x) find(a.begin(),a.end(),x)
#define vstart auto startt=chrono::system_clock::now()
#define vend auto endd=chrono::system_clock::now()
#define vvreme chrono::duration<double> vremee=endd-startt
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define vece(x,y) x=min(x,y);

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
typedef string str;

const ll maxn=10001;
ll dp[maxn][10][(1<<10)];
ll cifre=2;

void solve(){
    str s;
    cin>>s;
    for(char i:s){
        if(i!='0' && i!='1') cifre=10;
    }
    ll n=s.size();
    for(ll i=0;i<n;i++){
        for(ll j=0;j<cifre;j++){
            for(ll mask=0;mask<(1<<cifre);mask++)
                dp[i][j][mask]=INT_MAX;
        }
    }
    ///
    for(ll cifra=0;cifra<cifre;cifra++){
        dp[0][cifra][(1<<cifra)]=((s[0]-'0')!=cifra ? 1:0);
    }
    ///
    ll res=INT_MAX;
    for(ll i=1;i<n;i++){
        for(ll cifra=0;cifra<cifre;cifra++){
            for(ll mask=0;mask<(1<<cifre);mask++){
                if(mask&(1<<cifra)){
                    vece(dp[i][cifra][mask],dp[i-1][cifra][mask]+((s[i]-'0')!=cifra ? 1:0));
                }else{
                    for(ll cifra2=0;cifra2<cifre;cifra2++){
                        if(!(mask&(1<<cifra2))) continue;
                        vece(dp[i][cifra][mask|(1<<cifra)],dp[i-1][cifra2][mask]+((s[i]-'0')!=cifra ? 1:0));
                    }
                }
                if(i==n-1)
                res=min(res,dp[i][cifra][mask]);
            }
        }
    }
    cout<<res;
}

int main(){
    ios;
    ll t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}