#include <bits/stdc++.h>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL) ; cout.tie(NULL) ;
    
    string s;
    long long int br,r=0,r1=0,pp=0;
    long long int a[10];
    
    for(int i=0;i<10;i++){
    	a[i]=0;
	}
	
	cin>>s;
	for(unsigned long long int i=0;i<s.length();i++){
		br=s[i]-'0';
		
		r1+=(a[br]==0?0:i-a[br]);
		if(a[br]<a[pp] && r1!=0){
			r=min(r,r1);
		}else{			
			r+=r1;	
			pp=br;
		}
		
		if(i==s.length()-1 && pp==0 && a[br]!=0) r=1;
		a[br]=i+1;
		//cout<<"i="<<i<<" r="<<r<<"\n";
	}
	cout<<r;
}