#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Pr pair<ll,ll>
#define Tp tuple<ll,ll,ll>
using Graph = vector<vector<int>>;

const ll mod = 998244353;

int main() {
    string S; cin >> S;
    int N = S.size();
    string T = S;
    reverse(T.begin(),T.end());
    if(S!=T){
        cout << N << endl; return 0;
    }
    set<char> ss;
    rep(i,N){
        //if(N%2==1&&i==(N/2)) continue;
        ss.insert(S[i]);
    }
    if(ss.size()>1&&N>=4){
        cout << N-2 << endl; return 0;
    }
    if(N%2==0){
        cout << 0 << endl; return 0;
    }
    cout << -1 << endl;
}