#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 main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> s;

    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 {

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


        unordered_map<char, int> recnik;
        for (int i = 0; i < s.size(); ++i)
            recnik[s[i]]++;
        unordered_map<char, int> recnik2 = recnik;

        int res1, res2;

        // RES 1
        string solution(s.size(), '0');
        int start;
        for (int i = 0; i < s.size(); ++i) {

            if (recnik[s[i]]-2 < 0) { start = i; break; }
            else {
                recnik[s[i]] -= 2;
                solution[i] = s[i];
                solution[s.size()-1-i] = s[i];
            }

        }

        // cout << "res1: " << solution << endl;
        for (int i = s.size()-1; i >= 0; i--)
            if (solution[i] != s[i]) {
                res1 = i-start+1;
                break;
            }


        // RES 2
        reverse(s.begin(),s.end());
        string solution2(s.size(), '0');
        int start2;
        for (int i = 0; i < s.size(); ++i) {

            if (recnik2[s[i]]-2 < 0) { start2 = i; break; }
            else {
                recnik2[s[i]] -= 2;
                solution2[i] = s[i];
                solution2[s.size()-1-i] = s[i];
            }

        }

        // cout << "res2: " << solution2 << endl;
        for (int i = s.size()-1; i >= 0; i--)
            if (solution2[i] != s[i]) {
                res2 = i-start2+1;
                break;
            }


        cout << min(res1, res2) << endl;
    }



    return 0;
}