#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;
    }



    return 0;
}