#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); string s; cin >> s; auto is_pal = [](string s) { return s == string(s.rbegin(), s.rend()); }; if(!is_pal(s)) { cout << s.size() << endl; } else { set st; for(char c : s) st.insert(c); if(st.size() == 1u) { if(s.size() % 2 == 0) { cout << 0 << endl; } else { cout << -1 << endl; } } else { cout << s.size() - 2u << endl; } } }