#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using uint = unsigned; using ull = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; bool is_palindrome(const string &s, char c = '?'){ auto n = s.length(); for (int i = 0; i < (n+1)/2; ++i) { if(s[i] == c || s[n-i-1] == c) continue; if(s[i] != s[n-i-1]) return false; } return true; } int main() { string s; cin >> s; int same = 1; int n = s.size(); for (int i = 0; i+1 < n; ++i) { if(s[i] != s[i+1]) same = 0; } if(same){ puts(n%2 == 0 ? "0" : "-1"); return 0; }else if(!is_palindrome(s)) { cout << n << "\n"; }else if(n != 3) { cout << n-2 << "\n"; }else { cout << -1 << "\n"; } return 0; }