#include <bits/stdc++.h>
using namespace std;
string s;
int p,k,x;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin>>s;
    p=s.find("b");
    k=s.find_last_of("b");
    if((s.length()-k-1-p)>=0)
        x=s.length()-k-p;
    else
        x=p-(s.length()-k-1)+1;
    cout<<x;
}