#include <bits/stdc++.h>

#define vi vector<int>
#define vvi vector<vi >
#define rang(X,Y,Z) max((Y>0) ? (X[Z]-X[Y-1]):(X[Z]),0)


using namespace std;

string s;
int n;


bool valid(int m,vi& srq_bad_seq ,vvi& srq_cnt){


    for(int i=0;i<(n-m)/2;i++){
        if(rang(srq_bad_seq,i,i+m) + rang(srq_bad_seq,n-1-(m+i),n-i-1)-rang(srq_bad_seq,n-1-(m+i),i+m)==rang(srq_bad_seq,0,n-1)){
            int x=0,t=0;
            for(int j=0;j<26;j++){
                int seg1=rang(srq_cnt[j],i,i+m);                      ///***AAAAA*****
                int seg2=rang(srq_cnt[j],max(i+m+1,n-1-(i+m)),n-1-i); ///*****AAABB***

                if(seg1>=seg2){
                    if((seg1-seg2)%2)x++;
                }
                else t++;
            }
            if(x<2 && t<1){
                return 1;
            }

            x=0,t=0;
            for(int j=0;j<26;j++){
                int seg1=rang(srq_cnt[j],n-1-(i+m),n-1-i);                ///*****BBBBB***
                int seg2=rang(srq_cnt[j],i ,min(i+m , n-1-(i+m+1)));        ///***AABBB*****

                if(seg1>=seg2){
                    if((seg1-seg2)%2)x++;
                }
                else t++;
            }
            if(x<2 && t<1){
                return 1;
            }
        }
    }


    return 0;
}


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>s;

    n=s.length();


    vi srq_bad_seq(n);
    vvi srq_cnt (26,vi(n,0));

    srq_bad_seq[0] = s[0]!=s[n-1];
    srq_cnt[s[0]-'a'][0]++;


    for(int i=1;i<n;i++){
        srq_bad_seq[i]= srq_bad_seq[i-1]+(s[i]!=s[n-1-i]);
        for(int j=0;j<26;j++){
            srq_cnt[j][i]=srq_cnt[j][i-1];
        }
        srq_cnt[s[i]-'a'][i]++;
    }

    int l=1, r=n;
    while(l<r){
        int mid=(l+r)/2;

        if(valid(mid-1,srq_bad_seq,srq_cnt)) r = mid;
        else l=mid+1;


    }

    cout << l << endl;
    return 0;
}