#include <bits/stdc++.h>
using namespace std;

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define mp make_pair
#define parll pair<ll,ll>
#define parii pair<int,int>
#define nzd __gcd
#define nzs(e1,e2) (e1/nzd(e1,e2))*e2
#define min3(brp1,brp2,brp3) min(brp1,min(brp2,brp3))
#define min4(brp1,brp2,brp3,brp4) min(brp1,min3(brp2,brp3,brp4))
#define max3(brp1,brp2,brp3) max(brp1,max(brp2,brp3))
#define max4(brp1,brp2,brp3,brp4) max(brp1,max3(brp2,brp3,brp4))
#define l_b(BRL,brl) lower_bound( BRL.begin(), BRL.end(), brl )-BRL.begin()-1 /// !za one based! vraca mani iako brl postoji, vraca 0 kada ne postoji manji
#define u_b(BRU,bru) upper_bound( BRU.begin(), BRU.end(), bru )-BRU.begin() /// !za one based! vraca veci iako bru postoji, vraca n+1 kada ne postoji veci
#define mod 1000000007
#define mx 1000002

ll n,B[26],B1[26],B2[26];
string s;

ll Neparan( ll poz1, ll poz2 )
{
//    for ( ll i = 0; i < 26; i++ )
//    {
//        if ( B1[i] != B2[i] )
//        {
//            return poz2-poz1+1;
//        }
//    }
//    for ( ll i = 0; i < 26; i++ )
//    {
//        if ( (B1[i]+B2[i])%2 != 0 )
//        {
//            return -1;
//        }
//    }
    ll C[26];
    for ( ll i = 0; i < 26; i++ )
    {
        C[i] = B[i];
    }
    ll rez1=poz2-poz1+1,rez2=poz2-poz1+1;
    for ( ll i = poz1; i <= poz2; i++ )
    {
        if ( B[s[i]-'a']-1 == 0 )
        {
            break;
        }
        B[s[i]-'a']--;
        rez1--;
    }
    for ( ll i = poz2; i >= poz1; i-- )
    {
        if ( C[s[i]-'a']-1 == 0 )
        {
            break;
        }
        C[s[i]-'a']--;
        rez2--;
    }
    return min(rez1,rez2);
}

ll Paran( ll poz1, ll poz2 )
{
//    for ( ll i = 0; i < 26; i++ )
//    {
//        if ( B1[i] != B2[i] )
//        {
//            return poz2-poz1+1;
//        }
//    }
//    for ( ll i = 0; i < 26; i++ )
//    {
//        if ( (B1[i]+B2[i])%2 != 0 )
//        {
//            return -1;
//        }
//    }
    ll rez = poz2-poz1+1;
    for ( ll i = poz1; i <= poz2; i++ )
    {
        if ( B[s[i]-'a']-1 == 0 )
        {
            break;
        }
        B[s[i]-'a']--;
        rez--;
    }
    return rez;
}

ll Resi()
{
    ll poz1=0,poz2=0;
    for ( ll i = 1; i <= n/2; i++ )
    {
        if ( s[i] != s[n-i+1] )
        {
            poz1 = i;
            break;
        }
    }
    if ( poz1 == 0 )
    {
        return 1;
    }
    poz2 = n-poz1+1;
    for ( ll i = poz1; i <= n/2; i++ )
    {
        B1[s[i]-'a']++;
    }
    for ( ll i = n/2+1+(n&1); i <= poz2; i++ )
    {
        B2[s[i]-'a']++;
    }
    for ( ll i = 1; i <= n; i++ )
    {
        B[s[i]-'a']++;
    }
    bool svi_isti = true;
    for ( ll i = 0; i < 26; i++ )
    {
        if ( B1[i] != B2[i] )
        {
            svi_isti = false;
            break;
        }
    }
    if ( svi_isti )
    {
        return n/2-poz1+1;
    }
    if ( n&1 )
    {
        return Neparan(poz1,poz2);
    }
    return Paran(poz1,poz2);
}

int main()
{
    ios;

    cin >> s;
    n = s.size();
    s = '0'+s;
    cout << Resi();

    return 0;
}