#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); string s; cin >> s; { string t = s; reverse(t.begin(), t.end()); if (s != t) { cout << s.size() << '\n'; return 0; } } set st(s.begin(), s.end()); if (st.size() == 1) { cout << (s.size() % 2 == 0 ? 0 : -1) << '\n'; } else { cout << (s.size() == 3 ? -1 : (int) s.size() - 2) << '\n'; } return 0; }