#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

/*
for (int i = 0; i < n; i++)
{
	if (frequencies.find(s[i]) == frequencies.end()) {
		frequencies[s[i]] = 1;
	}
	else {
		frequencies[s[i]]++;
	}
}
*/

bool is_palindrome(string s)
{
	int n = s.size();
	for (int i = 0; i < n/2; i++)
	{
		if (s[i] != s[n-i-1])
			return false;
	}
	return true;
}

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	map<char,int> frequencies;
	if (is_palindrome(s))
	{
		cout << "1\n";
	}
	else
	{
		int bc = 0;
		for (int i = 0; i < n; i++)
		{
			if (s[i] == 'b')
			{
				bc++;
			}
			else if (s[i] != 'a')
			{
				bc = 3;
			}
		}
		if (bc == 2)
		{
			int b1=-1, b2=-1;
			for (int i = 0; i < n; i++)
			{
				if (s[i] == 'b')
				{
					if (b1 == -1)
					{
						b1 = i;
					}
					else
					{
						b2 = i;
					}
				}
			}
			int diff = (n-1-b2) - b1 + 1;
			cout << diff << "\n";
		}
		else
		{
			cout << 4 << "\n";
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}