#include <bits/stdc++.h>

using namespace std;

int main() {
    string rec;
    cin >> rec;
    int n = rec.length();
    int sol = n;
    int pocetak = -1;
    unordered_map<char, int> desno, levo, celo;
    bool jePalindram = true;
    for(int i = 0; i < n / 2; i++) {
        if(rec[i] == rec[n - 1 - i]) {
            sol -= 2;
            continue;
        }
        pocetak = i;
        break;
    }
    if(pocetak == -1) {
        cout << 1 << endl;
        return 0;
    }
    for(int i = 0; i < sol; i++) celo[rec[i]]++;

    int resenje = sol;

    for(int i = pocetak; i < pocetak + sol; i++) {
        levo[rec[i]]++;
        if(celo[rec[i]] - levo[rec[i]] >= levo[rec[i]]) {
            sol--;
            continue;
        }
        break;
    }
    swap(sol, resenje);

    for(int i = pocetak + sol - 1; i >= pocetak; i--) {
        desno[rec[i]]++;
        if(celo[rec[i]] - desno[rec[i]] >= desno[rec[i]]) {
            sol--;
            continue;
        }
        break;
    }
    resenje = min(resenje, sol);
    cout << resenje << endl;
    return 0;
}