a = input()
n = len(a)
q = 0
while q < n and a[q] == a[n - q - 1] == "a":
	q += 1
if q == n - 1:
	print(0)
else:	
	if q > 0:
		q -= 1
	z = q	
	n = n - q	
	maximum = 0
	ind = False
	begin = True
	if a[z] != "a":
		begin = False
	i = z
	count = 0	
	if begin:
		while i < n and a[i] == "a":
			i += 1
		if i == n - 1:
			print(n - z)
		else:
			maximum = i - z
			for i in range(i, n):
				if not ind and a[i] == "a":
					ind = True
					count = 1
				elif ind and a[i] == "a":
					count += 1
				elif ind and a[i] != a:
					x = (count // 2) + (count % 2)
					ind = False
					if x > maximum:
						maximum = x
					count = 0
			if ind:
				x = count
				ind = False
				if x > maximum:
					maximum = x
			print(maximum)
	else:
		maximum = i - z
		for i in range(i, n):
			if not ind and a[i] == "a":
				ind = True
				count = 1
			elif ind and a[i] == "a":
				count += 1
			elif ind and a[i] != a:
				x = (count // 2) + (count % 2)
				ind = False
				if x > maximum:
					maximum = x
				count = 0
		if ind:
			x = count
			ind = False
			if x > maximum:
				maximum = x
		print(maximum)

					
				


				
				
		



