#include using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define Pr pair #define Tp tuple using Graph = vector>; const ll mod = 998244353; int main() { string S; cin >> S; int N = S.size(); string T = S; reverse(T.begin(),T.end()); if(S!=T){ cout << N << endl; return 0; } set ss; rep(i,N){ if(N%2==1&&i==(N/2)) continue; ss.insert(S[i]); } if(ss.size()>1){ cout << N-2 << endl; return 0; } if(N%2==0){ cout << 0 << endl; return 0; } cout << -1 << endl; }