// __builtin_popcount(x) broj bitova
// __builtin_popcountll(x) long long
#define here cerr<<"---------------------------\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i = l;i<=r;i++) cerr<<a[i]<< " ";cerr<<endl;}
using namespace std;
#define maxn 200005
ll a[maxn];
ll n;
string s;
ll cnt1[30];
ll cnt2[30];
ll cnt3[30];
bool p[maxn];
bool pal(){
    ll l = 1,r = n;
    while(l<=r){
        if(a[l]!=a[r]) return 0;
        r--;
        l++;
    }
    return 1;
}
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
    cin >> s;
    n = sz(s);
    for(ll i = 1;i<=n;i++) a[i] = (s[i-1]-'a');
    if(pal()){
        cout<<1<<endl;
        return 0;
    }
    ll l = 1,r = n;
    while(l<=r){
        if(a[l]==a[r]){
            l++;
            r--;
        }else break;
    }
    ll mid = (l+r)/2;
    ll tl,tr;
    if((r-l+1)&1){
        p[1] = 1;
        tl = mid-1;
        tr = mid+1;
    }else{
        tl = mid;
        tr = mid+1;
    }
    p[0] =  1;
    while(tl>=l&&tr<=r){
        if(a[tl]!=a[tr]) break;
        p[tr-tl+1] = 1;
        tr++;
        tl--;
    }
    ll ans = llinf;
    for(ll i = l+1;i<=r;i++) cnt2[a[i]]++;
    cnt1[a[l]]++;
    for(ll i = l+1;i<=r;i++){
        cnt1[a[i]]++;
        cnt2[a[i]]--;
        for(ll i = 0;i<30;i++) cnt3[i] = cnt1[i]-cnt2[i];
        ll e = 0;
        ll re = 0;
        ll rc = 0;
        for(ll i = 0;i<30;i++){
            if(cnt3[i]<0) cnt3[i]*=-1,re++;
            else if(cnt3[i]>0) rc++;
            if(cnt3[i]&1) e++;
        }
        if(re>0&&rc>0) continue;
        if(i-l+1>r-i){
            if(e==((tr-tl+1)&1)){
                ans = min(ans,i-l+1);
                break;
            }
        }else{
            if(rc==0&&p[r-l+1-2*(i-l+1)]){
                ans = min(ans,i-l+1);
                break;
            }
        }
    }
    fill(cnt1,cnt1+30,0);
    fill(cnt2,cnt2+30,0);
    tl = l,tr = r;
    while(tl<=tr){
        swap(a[tl],a[tr]);
        tl++;
        tr--;
    }
    for(ll i = l+1;i<=r;i++) cnt2[a[i]]++;
    cnt1[a[l]]++;
    for(ll i = l+1;i<=r;i++){
        cnt1[a[i]]++;
        cnt2[a[i]]--;
        for(ll i = 0;i<30;i++) cnt3[i] = cnt1[i]-cnt2[i];
        ll e = 0;
        ll re = 0;
        ll rc = 0;
        for(ll i = 0;i<30;i++){
            if(cnt3[i]<0) cnt3[i]*=-1,re++;
            else if(cnt3[i]>0) rc++;
            if(cnt3[i]&1) e++;
        }
        if(re>0&&rc>0) continue;
        if(i-l+1>r-i){
            if(e==((tr-tl+1)&1)){
                ans = min(ans,i-l+1);
                break;
            }
        }else{
            if(rc==0&&p[r-l+1-2*(i-l+1)]){
                ans = min(ans,i-l+1);
                break;
            }
        }
    }
    cout<<ans<<endl;
	return 0;
}