#include <bits/stdc++.h>
#define pb push_back
#define sc scanf
#define pr printf
#define tc int t; cin>>t; while(t--)
#define ccout if(debug) cout

typedef long long ll;
using namespace std;
const int mxN=100010,mxM=1005,mod=1e9+7;
string s, s1;
int sol, bro[134];

string stoint(int x){
   string ret="";
   while(x>0){
      ret.pb('0'+x%10);
      x/=10;
   }
   reverse(ret.begin(), ret.end());

   return ret;
}
bool cvrst(int x){
   s1=stoint(x);
   int kraj=s1.size()-1;
   memset(bro, 0, sizeof(bro));
   for(int i=0; i<=kraj; i++){
      if(i==kraj){
         if(bro[s1[i]-'0']==1){
            return 0;
         }
         break;
      }
      int pp=i;
      while(s1[i]==s1[i+1] && i<kraj){
         i++;
      }

      if(bro[s1[pp]-'0']==1){
         return 0;
      }
      bro[s1[pp]-'0']=1;
   }

   return 1;
}
int uporedi(){
   while(s1.size()<s.size()) s1="0"+s1;
   int ret=0;
   for(int i=0; i<s.size(); i++) if(s1[i]!=s[i]) ret++;
   return ret;
}

int main(){
   cin>>s;
   sol=100;
   int kraj=1;
   for(int i=0; i<s.size(); i++) kraj*=10;

   for(int i=1; i<kraj; i++){
      if(cvrst(i)){
//         cout<<"yes ";
         sol=min(uporedi(), sol);
      }
//      cout<<i<<endl;
   }

   cout<<sol<<endl;

   return 0;
}