#include <bits/stdc++.h>
#define fi first
#define se second

using namespace std;
struct Border{
    int BorderLocation,BorderWeakness; //BorderLoc=0 |1,2,3,4 ;; BorderLoc=3 1,2,3|4
    vector<int> Infront;

};
string s;
int n,idxx=0;
int border=0;
vector<bool> ignore(10,true);
vector<int> InfrontBorder(10,0);
vector<int> BehindBorder(10,0);

Border BestBorderForK(int digit){
    Border b;
    b.BorderWeakness=InfrontBorder[digit];
    b.Infront=InfrontBorder;
    b.BorderLocation=0;
    vector<int> Infront=InfrontBorder;
    int behind=0;
    for(int i=border;i<n;i++){
        int d=s[i]-'0';
        if(ignore[d]) continue;
        if(d!=digit)
            behind++;
        Infront[d]--;
        if(b.BorderWeakness>behind+Infront[digit]){
            b.BorderWeakness=behind+Infront[digit];
            b.Infront=Infront;
            b.BorderLocation=i+1;
        }
    }
    return b;
}

int main()
{

    cin>>s;
    n=s.size();

    for(int i=0;i<n;i++){
        InfrontBorder[s[i]-'0']++;
        ignore[s[i]-'0']=false;
    }
    int res=0;

    while(border!=n){
        Border naj;
        naj.BorderWeakness=-1;
        for(int k=0;k<10;k++){
            if(ignore[k])continue;
            Border b=BestBorderForK(k);
            if(naj.BorderWeakness>b.BorderWeakness||(naj.BorderWeakness==b.BorderWeakness&&naj.BorderLocation<b.BorderLocation)||naj.BorderWeakness==-1)
                naj=b;
        }
        border=naj.BorderLocation;
        InfrontBorder=naj.Infront;
        res+=naj.BorderWeakness;

    }

    cout << res << endl;
    return 0;
}