#include using namespace std; using ll = long long int; using ld = long double; const ll MAX = 5000000000000000000; const ld PI = 3.14159265358979; const ll MOD = 0;//2024948111; ld dotorad(ld K){return PI * K / 180.0;} ld radtodo(ld K){return K * 180.0 / PI;} mt19937 mt; void randinit(){srand((unsigned)time(NULL));mt = mt19937(rand());} int main(){ string S; cin >> S; ll N = S.size(); for(ll i = 0;i < N;i++){ if(S[i] != S[N - 1 - i]){ cout << N << endl; return 0; } } if(N % 2 == 0){ vector A(500,0); ll a = 0; for(ll i = 0;i < N / 2;i++){ if(A[S[i] - 'a'] == 0){ a++; A[S[i] - 'a'] = 1; } } if(a >= 2){ cout << N - 2 << endl; return 0; } cout << 0 << endl; } else{ ll m = N / 2; vector A(500,0); ll a = 0; for(ll i = 0;i < m;i++){ if(A[S[i] - 'a'] == 0){ a++; A[S[i] - 'a'] = 1; } } if(a >= 2){ cout << N - 2 << endl; return 0; } if(N <= 3){ cout << -1 << endl; return 0; } if(S[0] == S[m]){ cout << -1 << endl; return 0; } cout << N - 2 << endl; return 0; } }