#include <iostream>
#define forn(i, n) for (int i = 0; i < n; i++)
using namespace std;
bool ok(int c1[32], int c2[32]) {
    forn(i, 32) if (c1[i] < c2[i]) return false;
    return true;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    string s;
    cin >> s;
    int n = s.size();

    int l = 0, r = n-1;
    while (l <= r && s[l] == s[r]) l++, r--;
    if (l > r) {
        cout << 1 << endl;
        return 0;
    }

    int lc = (n - 1) / 2, rc = n / 2;
    while (s[lc] == s[rc]) lc--, rc++;

    int cleft[32] = {0};
    int cright[32] = {0};
    int cpatrljak[32] = {0};
    for (int i = l; i <= r; i++) cpatrljak[s[i] - 'a']++;

    int minl = n * 2;

    for (int i = l; i <= r; i++) {
        cpatrljak[s[i] - 'a']--;
        cleft[s[i] - 'a']++;
        cright[s[r - (i - l)] - 'a']++;

        if (i < lc) continue;
        if (i < n / 2) {
            // check if c(s[l..i]) == c(s[r-i..r]) (moze >=)
            if (ok(cleft, cright)) minl = min(minl, i - l + 1);
        } else {
            // check if c(s[l..i]) >= c(s[i+1..r])
            if (ok(cleft, cpatrljak)) minl = min(minl, i - l + 1);
        }
    }

    forn(i, 32) cleft[i] = cright[i] = cpatrljak[i] = 0;
    for (int i = l; i <= r; i++) cpatrljak[s[i] - 'a']++;

    for (int i = r; i >= l; i--) {
        cpatrljak[s[i] - 'a']--;
        cright[s[i] - 'a']++;
        cleft[s[l + (r - i)] - 'a']++;

        if (i > rc) continue;
        if (i > (n - 1) / 2) {
            if (ok(cright, cleft)) minl = min(minl, r - i + 1);
        } else {
            if (ok(cright, cpatrljak)) minl = min(minl, r - i + 1);
        }
    }

    cout << minl << endl;

    #ifdef CHUNGUS
    system("pause");
    #endif
}