#include #include #include #include #include #include #include #include #include #include #include #include #include //#include #define ll long long #define rep(i, n) for(ll i = 0; i < n; i++) using namespace std; //using namespace atcoder; const ll INF = 1e18; /* ll gcd(ll a, ll b){ //log max(a,b) if (a % b == 0){ return(b); } else{ return(gcd(b, a % b)); } } ll lcm(ll a, ll b){ return a * b / gcd(a, b); } */ //gcd lcm /* class UnionFind { public: vector par; void init(ll sz) { par.resize(sz, -1); } ll root(ll pos) { if (par[pos] == -1) return pos; par[pos] = root(par[pos]); return par[pos]; } void unite(ll u, ll v) { u = root(u); v = root(v); if (u == v) return; par[u] = v; } bool same(ll u, ll v) { if (root(u) == root(v)) return true; return false; } }; */ typedef pair P; int main() { map mp; string s; cin >> s; bool p = true; if (s.size() == 1) { cout << -1 << endl; return 0; } rep(i, (ll)s.size()) { mp[s[i]]++; } if (mp.size() == 1) { if (s.size() % 2) cout << 1 << endl; else cout << 0 << endl; return 0; } for (ll i = 0; i < (ll)s.size() / 2; i++) { if (s[i] != s[s.size() - i - 1]) p = false; } if (!p) cout << s.size() << endl; else { cout << s.size() - 2 << endl; } return 0; }