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

namespace _C__Palindrom_Safl
{
    class Program
    {
        public static string Reverse(string s)
        {
            char[] niz = s.ToCharArray();
            Array.Reverse(niz);

            return new string(niz);
        }
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string s1 = Reverse(s);

            if (s == s1)
            {
                Console.WriteLine(1);
                return;
            }

            int poz1, poz2;

            poz1 = s.IndexOf('b');
            poz2 = s.LastIndexOf('b');

            int min, mins;
            
            mins = poz2 - poz1;
            min = Math.Abs(s.Length - poz2 - poz1);

            if (min == 0)
            {
                min = 2;
            }

            Console.WriteLine(min <= mins ? min : mins);

        }
    }
}