using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Palindrom_safl
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int i = s.IndexOf('b');
            int j = s.LastIndexOf('b');
            int n = s.Length;
            int x = n / 2;
            if (j <= x || i < n - j - 1)
                Console.WriteLine(n - i - j);
            else
                Console.WriteLine(i - n + j + 2);
        }
    }
}