#include using namespace std; int main() { string s; cin >> s; int n = s.size(); int k = count(s.begin(), s.end(), s[0]); if(n == k) puts(n & 1 ? "-1" : "0"); else { if(s == string{s.rbegin(), s.rend()}) cout << n - 2 << endl; else cout << n << endl; } }