#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
using namespace std;
const int N = 1e5 + 2;
const ll mod = 1e9 + 7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    vector<int> cnt(26);
    vector<int> ind;
    int l = 0, r = n - 1;
    while (l < r) {
        if (s[l] != s[r]) ind.push_back(l);
        cnt[s[l] - 'a'] += 1;
        cnt[s[r] - 'a'] -= 1;
        l += 1;
        r -= 1;
    }
    if (ind.empty()) {
        cout << 1 << en;
        return 0;
    }
    int ok = 1;
    for (int i = 0; i < 26; i++) {
        ok &= (cnt[i] == 0);
    }
    if (ok == 1) {
        cout << ind.back() - ind[0] + 1 << en;
        return 0;
    }
    string tmp;
    for (int i = ind[0]; i <= n - ind[0] - 1; i++) tmp += s[i];
    s = tmp;
    n = s.size();
    int ans = n - 1;
    for (int i = 0; i < 26; i++) cnt[i] = 0;
    for (int i = 0; i < n; i++) cnt[s[i] - 'a'] += 1;
    int bound = n / 2;
    ok = 1;
    for (int i = 0; i < bound; i++) {
        cnt[s[i] - 'a'] -= 2;
        if (cnt[s[i] - 'a'] < 0) ok = 0;
        if (ok == 1) ans = min(ans, n - i - 1);
    }
    reverse(s.begin(), s.end());
    for (int i = 0; i < 26; i++) cnt[i] = 0;
    for (int i = 0; i < n; i++) cnt[s[i] - 'a'] += 1;
    ok = 1;
    for (int i = 0; i < bound; i++) {
        cnt[s[i] - 'a'] -= 2;
        if (cnt[s[i] - 'a'] < 0) ok = 0;
        if (ok == 1) ans = min(ans, n - i - 1);
    }
    cout << ans << en;
    return 0;

}