#include using namespace std; int main () { string S; cin >> S; int N = S.size(); for (int i = 0; i < N; i ++) { if (S[i] != S[N - i - 1]) { cout << N << endl; return 0; } } if (N == 3) { cout << -1 << endl; return 0; } for (int i = 0; i < N / 2; i ++) { if (S[i] != S[i + 1]) { cout << N - 2 << endl; return 0; } } cout << (N % 2 ? -1 : 0) << endl; }