#include<bits/stdc++.h>
const int nmax = 2e5+1;
using namespace std;
map<int,int> cases,cases2;
char ar[nmax];
int l,r;
int main()
{
	cin >> ar;
	r=strlen(ar)-1;
	for(int i=0;i<strlen(ar);i++){
		cases[(int)ar[i]]++;
		cases2[(int)ar[i]]++;
	}
	for(;l<strlen(ar);l++)
	{
		if(cases[ar[l]]<2)break;
		cases[ar[l]]--;
	}
	for(;r>l;r--)
	{
		if(cases2[ar[r]]<2)break;
		cases2[ar[r]]--;
	}
	cout << r-l+1 << "\n";
}