#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<string>
using namespace std;
int main() {
	string str, st;
	cin >> str;
	st = str;
	int len = str.length(), i, j;
	for (i = 0, j = len - 1; i != j && i != j - 1; i++, j--) {
		if (str[i] == str[j]) {
			st = str.substr(i + 1, len - 2 * i - 2);
		}
		else break;
	}
	len = st.length();
	char l = st[0], r = st[len - 1];
	int brl = 0, brr = 0, lc = 0, rc = 0;
	for (i = 0; st[i] == l; i++)brl++;
	for (i = len - 1; st[i] == r; i--)brr++;
	for (i = 0; i < len; i++) {
		if (st[i] == l)lc++;
		else if (st[i] == r)rc++;
	}
	int idkl = (brl * 2 > lc ? lc / 2 : brl), idkr = (brr * 2 >= rc ? rc / 2: brr);
	cout << min(len - idkl, len - idkr);
}