#include <iostream>
#include <set>
using namespace std;

int ans=1e8;
string s;
set<char> has;

inline bool finish(string cur)
{
	for(int i=1;i<cur.size();i++) if(cur[i]!=cur[i-1]) return 0;
	return 1;
}

inline int solve(string cur,char fin)
{
	if(finish(cur)) return (s.size()-cur.size());
	for(int i=1;i<cur.size();i++) if(cur[i]==fin) cur[i-1]=fin;
	cur=cur.substr(0,cur.size()-1);
	return solve(cur,fin);
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>s;
	
	for(int i=0;i<s.size();i++)
	{
		if(has.count(s[i])) continue;
		ans=min(ans,solve(s,s[i]));
		has.insert(s[i]);
	}
	
	cout<<ans;
	
	return 0;
}