#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    string rec;
    cin>>rec;
    int b1,b2,res;
    b1=rec.find('b');
    b2=rec.rfind('b');
    if(b1==rec.length()-b2-1)
    {
        res=1;
    }
    else if(b1<rec.length()/2 && b2>rec.length()/2)
    {
        res=b2-b1+1;
    }
    else if(b1<rec.length()/2 && b2<=rec.length()/2)
    {
        if(rec.length()%2!=0)
        {
            res=rec.length()/2-b1+2;
        }
        else
        {
            res=rec.length()/2-b1+1;
        }
    }
    else
    {
        if(rec.length()%2!=0)
        {
            res=b2-rec.length()/2+2;
        }
        else
        {
            res=b2-rec.length()/2+1;
        }
    }
    if(abs(b1-rec.length()+b2+2)<res)
    {
        res=abs(b1-rec.length()+b2+2);
    }
    cout<<res;
    return 0;
}