#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  string S2 = S;
  reverse(S2.begin(), S2.end());
  if (S != S2){
    cout << S.size() << endl;
  } else if (S.size() == 1){
    cout << -1 << endl;
  } else {
    bool ok = true;
    for (int i = 0; i < S.size(); i++){
      if (S[i] != S[0]){
        ok = false;
      }
    }
    if (ok){
      if (S.size() % 2 == 0){
        cout << 0 << endl;
      } else {
        cout << -1 << endl;
      }
    } else {
      if (S.size() == 3){
        cout << -1 << endl;
      } else {
        cout << S.size() - 2 << endl;
      }
    }
  }
}