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

//      Starting Kit     (START)
typedef long long ll;
#define INF INT_MAX
#define MOD (1e9+7)

#define pii pair<int, int>
#define mp make_pair

#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vii vector<pii>
#define pb push_back
#define print_vect(v) for (auto it : v) cout << it << " ";
//      Starting Kit     (END)


string s;

is_palindrome(string s) {
    for (int i = 0, j = s.size()-1; i <= j; ++i, --j)
        if (s[i] != s[j]) return false;
    return true;
}


int resi(string s) {
    // RECNIK
    unordered_map<char, int> recnik;
    int n = s.size();
    for (int i = 0; i < n; ++i)
        recnik[s[i]]++;

    string sol1(n, '0');

    int res1;
    int start1;

    // PAR
    if (n%2==0) {
        for (int i = 0; i <= n/2; ++i) {
            if (recnik[s[i]]-2 >= 0) {
                recnik[s[i]] -= 2;
                sol1[i] = s[i];
                sol1[n-1-i] = s[i];
            } else {
                start1 = i;
                break;
            }
        }

        if (sol1[start1] != s[start1]) start1--;
        while (sol1[start1] == s[start1]) start1++;
        if (sol1[start1] != s[start1]) start1--;

        for (int i = n-1; i >= 0; i--)
            if (sol1[i] != s[i]) {
                res1 = i-start1;
                break;
            }

        //cout << sol1 << ", " << res1 << endl;
        return res1;
    }

    // NEPAR
    else {

        int i;
        for (i = 0; i <= n/2; ++i) {
            if (recnik[s[i]]-2 >= 0) {
                recnik[s[i]] -= 2;
                sol1[i] = s[i];
                sol1[n-1-i] = s[i];
            } else {
                start1 = i;
                break;
            }
        }

        if (recnik[s[i]] >= 1) sol1[i] = s[i];

        if (sol1[start1] != s[start1]) start1--;
        while (sol1[start1] == s[start1]) start1++;
        if (sol1[start1] != s[start1]) start1--;

        for (int i = n-1; i >= 0; i--)
            if (sol1[i] != s[i]) {
                res1 = i-start1;
                break;
            }

        //cout << sol1 << ", " << res1 << endl;
        return res1;
    }
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> s;
    string s1(s.rbegin(), s.rend());
    if (is_palindrome(s)) { cout << 1 << endl; return 0; }

    // PRVI PODZADATAK
    bool prvi_pod_zad = true;
    int broji_b = 0;
    for (auto c : s) {
        if (c != 'a' && c != 'b')
            prvi_pod_zad = false;
        if (c == 'b') ++broji_b;
    }
    if (prvi_pod_zad && broji_b == 2) {
        // dva b, ostala a

        if (is_palindrome(s)) { cout << 1; return 0;}


        int pos1, pos2;
        int i;
        for (i = 0; i < s.size(); ++i)
            if (s[i] == 'b') { pos1 = i; break; }

        ++i;
        for (;i < s.size(); ++i)
            if (s[i] == 'b') pos2 = i;


        if (s.back() == 'b') { cout << pos1+1; return 0; }
        if (s.front() == 'b') { cout << s.size()-pos2; return 0; }

        int razl1 = pos1;
        int razl2 = s.size()-1-pos2;
        cout << abs(razl1-razl2)+1 << endl;
    }
    else {
        int res1 = resi(s);
        int res2 = resi(s1);
        cout << min(res1, res2);
    }


    return 0;
}