#include <bits/stdc++.h>
#include <time.h>
using namespace std;

#define sz(x) ((int)(x).size())
#define pb push_back
#define vec vector
#define fi first
#define se second
#define ends "\n"
#define sp ' '
#define fun function
#define ar(x) array<int, x>
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const long long MOD=1e9+7; 

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

int odd(string s){
    int n = sz(s);
    int ans = n;

    //do pola

    vec<int> cntEv(26);
    for(int i = 0; i < n; ++i)
        cntEv[s[i] - 'a']++;

    char c = 'a';
    for(int i = 0; i < 26; ++i){
        if(cntEv[i] & 1){
            c = (char)('a' + i);
            break;
        }
    }

    vec<bool> isPalindromeRev(n);
    for(int i = n / 2; i >= 0; --i){
        if(i == n / 2){
            if(s[i] == c) isPalindromeRev[i] = true;
            else break;
        }else{
            if(s[i] == s[n - 1 - i]) isPalindromeRev[i] = true;
            else break;
        }
    }

    vec<int> cntL(26), cntR(26);
    int okCnt1 = 26;

    for(int i = 0; i < n / 2; ++i){
        int ind1 = s[i] - 'a';
        int ind2 = s[n - 1 - i] - 'a';
        int prevCntL1 = cntL[ind1], prevCntL2 = cntL[ind2];
        int prevCntR1 = cntR[ind1], prevCntR2 = cntR[ind2];
        ++cntL[ind1];
        ++cntR[ind2];

        if(cntL[ind1] != cntR[ind1] && prevCntL1 == prevCntR1)
            --okCnt1;

        if(cntL[ind2] != cntR[ind2] && prevCntL2 == prevCntR2)
            --okCnt1;

        if(cntL[ind1] == cntR[ind1] && prevCntL1 != prevCntR1)
            ++okCnt1;

        if(cntL[ind2] == cntR[ind2] && prevCntL2 != prevCntR2)
            ++okCnt1;
        
        if(isPalindromeRev[i + 1] && okCnt1 == 26){
            ans = min(ans, i + 1);
            break;
        }
    }

    fun<int()> calc = [&] (){
        vec<int> cntS(26), cntAll(26);
        for(int i = 0; i < n; ++i){
            if(i < n / 2)
                cntS[s[i] - 'a']++;
            else
                cntAll[s[i] - 'a']++;
        }

        int okCnt = 0;
        for(int i = 0; i < 26; ++i)
            if(cntS[i] >= cntAll[i])
                ++okCnt;

        for(int i = n / 2; i < n; ++i){
            int ind1 = s[i] - 'a';

            int prevCntS = cntS[ind1], prevCntAll = cntAll[ind1];

            ++cntS[ind1];
            --cntAll[ind1];

            if(cntS[ind1] >= cntAll[ind1]  && prevCntS < prevCntAll)
                ++okCnt;

            if(okCnt == 26)
                return i + 1;
        }
        return n;
    };

    ans = min(ans, calc());
    reverse(all(s));
    ans = min(ans, calc());

    return ans;
}

int even(string s){
    int n = sz(s);
    int ans = n;

    //do pola
    vec<int> cntL(26), cntR(26);
    vec<bool> isPalindromeRev(n);
    int okCnt1 = 26;

    for(int i = n / 2 - 1; i >= 0; --i){
        if(s[i] == s[n - 1 - i]) isPalindromeRev[i] = true;
        else break;
    }

    for(int i = 0; i < n / 2; ++i){
        int ind1 = s[i] - 'a';
        int ind2 = s[n - 1 - i] - 'a';
        int prevCntL1 = cntL[ind1], prevCntL2 = cntL[ind2];
        int prevCntR1 = cntR[ind1], prevCntR2 = cntR[ind2];

        ++cntL[ind1];
        ++cntR[ind2];

        if(cntL[ind1] != cntR[ind1] && prevCntL1 == prevCntR1)
            --okCnt1;

        if(cntL[ind2] != cntR[ind2] && prevCntL2 == prevCntR2)
            --okCnt1;

        if(cntL[ind1] == cntR[ind1] && prevCntL1 != prevCntR1)
            ++okCnt1;

        if(cntL[ind2] == cntR[ind2] && prevCntL2 != prevCntR2)
            ++okCnt1;
        
        if((i == (n / 2 - 1) || isPalindromeRev[i + 1]) && okCnt1 == 26){
            ans = min(ans, i + 1);
            break;
        }
    }

    fun<int()> calc = [&] (){
        vec<int> cntS(26), cntAll(26);
        for(int i = 0; i < n; ++i){
            if(i < n / 2)
                cntS[s[i] - 'a']++;
            else
                cntAll[s[i] - 'a']++;
        }

        int okCnt = 0;
        for(int i = 0; i < 26; ++i)
            if(cntS[i] >= cntAll[i])
                ++okCnt;

        for(int i = n / 2; i < n; ++i){
            int ind1 = s[i] - 'a';

            int prevCntS = cntS[ind1], prevCntAll = cntAll[ind1];

            ++cntS[ind1];
            --cntAll[ind1];

            if(cntS[ind1] >= cntAll[ind1]  && prevCntS < prevCntAll)
                ++okCnt;

            if(okCnt == 26)
                return i + 1;
        }
        return n;
    };

    ans = min(ans, calc());
    reverse(all(s));
    ans = min(ans, calc());

    return ans;
}

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
 	
    string s;
    cin >> s;
    int n = sz(s);

    int i1 = 0, i2 = n - 1;
    while(i1 <= i2 && s[i1] == s[i2]){
        ++i1;
        --i2;
    }

    if(i1 > i2){
        cout << 1 << ends;
        return 0;
    }

    string newS = "";
    for(int i = i1; i <= i2; ++i)
        newS = newS + s[i];
    
    if(n & 1)
        cout << odd(newS) << ends;
    else
        cout << even(newS) << ends;
 	
}