#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char s[200005];
int cnt[10],ed[200005][10];
int main(){
scanf("%s",s+1);
int l=strlen(s+1);
memset(cnt,0,sizeof(cnt));
for (int i=1; i<=l; i++)
cnt[s[i]-'0']++;
for (int j=0; j<10; j++)
ed[l+1][j]=l+1;
for (int i=l; i>=1; i--){
for (int j=0; j<=9; j++)
ed[i][j]=ed[i+1][j];
ed[i][s[i]-'0']=i;
}
int res=0;
for (int i=0; i<=9; i++){
if (cnt[i]==0) continue;
res=max(res,cnt[i]);
for (int j=0; j<=9; j++){
if (cnt[j]==0) continue;
if (i!=j){
int st=ed[1][i],tot=0,flag=1;
while (st<=l){
tot++;
if (flag) {
if (ed[st+1][j]>l) break;
st=ed[st+1][j];
}
else {
if (ed[st+1][i]>l) break;
st=ed[st+1][i];
}
flag=flag^1;
}
if (tot%2==1) tot--;
res=max(res,tot);
}
}
}
printf("%d\n",l-res);
}