#include using namespace std; int main() { string S; cin >> S; string T = S; reverse(T.begin(),T.end()); string R = S; sort(R.begin(),R.end()); if(S == T) { if(S.size() == 3 || (S.size()%2 && R.front() == R.back())) { cout << -1 << endl; } else if(R.front() == R.back()) { cout << 0 << endl; } else { cout << S.size()-2 << endl; } } else { cout << S.size() << endl; } }