#include <bits/stdc++.h>
using namespace std;
bool check1[125], check2[125], check3[125], check4[125], check5[125], check6[125];
bool isPalindrome(string S){
    for (int i = 0; i < S.length() / 2; i++) {
        if (S[i] != S[S.length() - i - 1]) {
            return false;
        }
    }
    return true;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cerr.tie(0); cout.tie(0);
	string s;
	cin >> s;
	long long res = 1;
	long long n = s.length();
	if(isPalindrome(s))
		cout << 1;
	else if(n == 3)
		cout << 2;
	else{
		for(int i = 0; i < n / 2; i++){
			if(s[i] == s[n - i - 1])
				continue;
			else{
				// pokusaj za pola stringa
				long long levi[123];
				long long desni[123];
				long long rez = 1e17;
				for(int j = 90; j < 123; j++){
					levi[j] = 0;
					desni[j] = 0;
				}
				long long sum = 0;
				bool pal = true;
				for(int j = i; j < n / 2; j++){
					levi[s[j]]++;
					desni[s[n - j - 1]]++;
					/*for(int m = 97; m < 123; m++)
						cout << levi[m] << " ";
					cout << endl;
					for(int m = 97; m < 123; m++)
						cout << desni[m] << " ";
					cout << endl;*/
					
					if(levi[s[j]] == desni[s[j]] && !check3[s[j]] && !check3[s[n - j - 1]]){
						sum--;
						check3[s[j]] = true;
						check3[s[n - j - 1]] = true;
						//cout << "check3" << endl;
					}
					if(levi[s[j]] != desni[s[j]] && !check4[s[j]] && !check4[s[n - j - 1]]){
						sum++;
						check4[s[j]] = true;
						check4[s[n - j - 1]] = true;
						//cout << "check4" << endl;
					}
					if(levi[s[n - j - 1]] == desni[s[n - j - 1]] && check5[s[n - j - 1]] == 0 & !check5[s[j]]){
						sum--;
						check5[s[n - j - 1]] = true;
						check5[s[j]] = true;
						//cout << "check5" << check5[s[n - j - 1]] << endl;
					}
					if(levi[s[n - j - 1]] != desni[s[n - j - 1]] && !check6[s[n - j - 1]] && !check6[j]){
						sum++;
						check6[s[n - j - 1]] = true;
						check6[s[j]] = true;
						//cout << "check6" << endl;
					}
					//cout << sum << endl << endl;
					if(sum <= 0){
						long long pom = 1;
						for(int a = j + 1; a < n - j - 1; a++){
							pom++;
							if(s[a] != s[n - a - 1] && a < n - a - 1){
								pal = false;
								break;
							}
						}
						if(pal){
						    //cout << endl << "pal" << endl << endl;
							rez = j + 1 - i;
							//cout << "evo ga " << i << " " << j << endl;
						}
						break;
					}
				}
				// pokusaj za vise od pola stringa
				long long uk[123];
				for(int m = 0; m<123; m++){
				    uk[m] = 0;
				    desni[m] = 0;
				    levi[m] = 0;
				}
				for(int j = 90; j < 123; j++)
					uk[j] = 0;
				for(int j = i; j < n - i; j++)
					uk[s[j]]++;
				for(int j = 90; j < 123; j++){
					desni[j] = 0;
					levi[j] = 0;
				}
				sum = 0;
				for(int k = 97; k < 123; k++){
					if(uk[k] > 0)
						sum++;
				}
				for(int j = n - i - 1; j >= i; j--){
					desni[s[j]]++;
					uk[s[j]]--;
					if(desni[s[j]] >= uk[s[j]] && !check1[s[j]]){
						sum--;
						check1[s[j]] = true;
					}
					if(desni[s[j]] < uk[s[j]] && check1[s[j]]){
						sum++;
						check1[s[j]] = false;
					}
					/*for(int m = 97; m<=123; m++)
					    cout << uk[m] << " ";
				    cout << endl;
				    for(int m = 97; m<=123; m++)
					    cout << desni[m] << " ";
				    cout << endl;
				    cout << sum << endl << endl;*/
					if(sum == 0){
						rez = min(rez, n - (long long)j - (long long)i);
						//cout << endl << n - (long long)j - (long long)i << endl << endl;
						//cout << "j: " << j << "  i: " << i << endl << endl;
						break;
					}
				}

				for(int j = 90; j < 123; j++)
					uk[j] = 0;
				for(int j = i; j < n - i; j++)
					uk[s[j]]++;
				for(int j = 90; j < 123; j++){
					desni[j] = 0;
					levi[j] = 0;
				}
				sum = 0;
				for(int k = 97; k < 123; k++){
					if(uk[k] > 0)
						sum++;
				}
				for(int j = i; j <= n - i - 1; j++){
					desni[s[j]]++;
					uk[s[j]]--;
					if(desni[s[j]] >= uk[s[j]] && !check2[s[j]]){
						sum--;
						check2[s[j]] = true;
					}
					if(desni[s[j]] < uk[s[j]] && check2[s[j]]){
						sum++;
						check2[s[j]] = false;
					}
					/*for(int m = 97; m<=123; m++)
					    cout << desni[m] << " ";
					cout << endl;
					for(int m = 97; m<=123; m++)
					    cout << uk[m] << " ";
					cout << endl;
					cout << sum << endl << endl;*/
					if(sum == 0){
						rez = min(rez, (long long)j - (long long)i + 1ll);
						break;
					}
				}
				cout << rez;
				break;
			}
		}
	}
	return 0;
}