#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll minBr(string t) {
    string h = t;
    ll len = t.length();
    ll l = 0;
    ll r = len - 1;
    ll minIndex = len;
    ll helpLen = len;
    ll maxIndex = -1;
    while (true) {
        if (t.length() == 0) break;
        if (t[0] == t[t.length() - 1]) {
            l++;
            r--;
            t = t.substr(1, t.length() - 2);
            continue;
        }
        size_t found = t.find(t[t.length() - 1]);
        if (found == t.length() - 1) {
            maxIndex = l + found;
            break;
        }
        minIndex = min(minIndex, l);
        ll rez = found + l;
        maxIndex = max(maxIndex,rez);
        char help = t[0];
        t[0] = t[found];
        t[found] = help;
    }
    if (minIndex == helpLen) return 1;
    return maxIndex - minIndex + 1;
}
ll minBrN(string t) {
    string h = t;
    ll len = t.length();
    ll l = 0;
    ll r = len - 1;
    ll minIndex = len;
    ll helpLen = len;
    ll maxIndex = -1;
    while (true) {
        if (t.length() == 0 || t.length()==1) break;
        if (t[0] == t[t.length() - 1]) {
            l++;
            r--;
            t = t.substr(1, t.length() - 2);
            continue;
        }
        size_t found = t.find(t[t.length() - 1]);
        if (found == t.length() - 1) {
            maxIndex = l + found;
            break;
        }
        minIndex = min(minIndex, l);
        ll rez = found + l;
        maxIndex = max(maxIndex, rez);
        char help = t[0];
        t[0] = t[found];
        t[found] = help;
    }
    if (minIndex == helpLen) return 1;
    return maxIndex - minIndex + 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string t,h;
    cin >> t;
    h = t;
    reverse(h.begin(), h.end());
    if (t.length() % 2 == 0) {
        cout << min(minBr(t), minBr(h)) << endl;
    }
    else {
        //odsecam iste
        while (true) {
            if (t.length() == 0 || t.length() == 1) break;
            if (t[0] == t[t.length() - 1]) {
                t = t.substr(1, t.length() - 2);
                continue;
            }
            else {
                break;
            }
        }
        //menjam smer ako treba 
        for (char ch : t) {
            if (t.length() == 1) break;
            if (count(t.begin(), t.end(), ch) == 1) {
                size_t f3 = t.find(ch);
                int sred = t.length() / 2;
                if (f3 > sred - 1) {
                    t = h;
                }
                break;
            }
        }
        cout << minBrN(t) << endl;
    }
}
//EZ