#include<bits/stdc++.h>
using namespace std;
string s;
int br,rbr,rabr,v;
int main(){
cin>>s;
    for(int i=0; s[i]!='b'; i++){
        br++;
    }

    for(int j=br+1; s[j]!='b'; j++){
        rbr++;
    }
    v+=s.size();
    rabr=v-br-rbr-2;


    if(s[0]=='b' and s[v-1]=='b'){
        cout<<0;
    }
    else if(s[0]=='b' or s[v-1]=='b'){
        cout<<s.size();
    }

    else if(br>rabr){
        cout<<rbr+2+(br-rabr);
    }
    else if(rabr>br){
        cout<<rbr+2+(rabr-br);
    }
    else if(br==rabr){
        cout<<0;
    }

  /*
cout<<rbr+2<<" "<<br<<" "<<rabr<<" "<<s.size();
*/
return 0;
}