#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    string t = s;
    reverse(t.begin(), t.end());
    if(s == t) {
    	cout << 1;
    	return 0;
    }
    int n = s.size();
    int l = 0, r = n-1;
    for(; l <= r; l++, r--) if(s[l] != s[r]) break;
    int ll = (n-1)/2, rr = n/2;
    for(; ll >= 0 && rr < n; ll--, rr++) if(s[ll] != s[rr]) break;
    int cnt[26];
    fill(cnt, cnt+26, 0);
    for(int i = l; i <= ll; i++) cnt[(int)(s[i] - 'a')]++;
    for(int i = rr; i <= r; i++) cnt[(int)(s[i] - 'a')]--;
    bool ok = true;
    for(int i = 0; i < 26; i++) if(cnt[i] != 0) {
    	ok = false;
    	break;
    }
    if(ok) {
    	cout << ll-l+1;
    	return 0;
    }
    int need[26];
    fill(need, need+26, 0);
    for(int i = l; i <= r; i++) need[(int)(s[i] - 'a')]++;
    for(int i = 0; i < 26; i++) need[i] = (need[i] + 1) / 2;
    int goal = 0;
    for(int i = 0; i < 26; i++) if(need[i]) goal++;
    fill(cnt, cnt+26, 0);
	bool mark[26];
	fill(mark, mark+26, false);
	int brojac = 0;
	int rez = 1e9;
    for(int i = l; i <= r; i++) {
    	int c = (int)(s[i] - 'a');
    	cnt[c]++;
    	if(cnt[c] >= need[c]) {
    		if(!mark[c]) brojac++;
    		mark[c] = true;
    	}
    	if(brojac == goal) {
    		rez = min(rez, i-l+1);
    		break;
    	}
    }
    fill(cnt, cnt+26, 0);
    fill(mark, mark+26, false);
    brojac = 0;
    for(int i = r; i >= l; i--) {
    	int c = (int)(s[i] - 'a');
    	cnt[c]++;
    	if(cnt[c] >= need[c]) {
    		if(!mark[c]) brojac++;
    		mark[c] = true;
    	}
    	if(brojac == goal) {
    		rez = min(rez, r-i+1);
    		break;
    	}
    }
    cout << rez;
    return 0;
}