#include using namespace std; using ll = long long; #define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++) void solve() { string s; cin >> s; string t(s.rbegin(), s.rend()); if(t != s) { cout << s.size() << endl; } else { if(s == string(s.size(), s.front())) { cout << (s.size() % 2 ? -1 : 0) << endl; } else { cout << s.size() - 2 << endl; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }