#include <bits/stdc++.h>

using namespace std;

int cnt[30];
int rem[30];
string s,sr;
int b;

void cl()
{
    for(int i = 0;i<29;i++)
    {
        cnt[i] = 0;
        rem[i] = 0;
    }
}

/*void testOut()
{
    for(int i = 0;i<4;i++)
        cout << cnt[i] << " ";
    cout << endl;
    for(int i = 0;i<4;i++)
        cout << rem[i] << " ";
    cout << endl << endl;
}*/

bool check()
{
    for(int i = 0;i< 29;i++)
    {
        if(cnt[i] < rem[i])
            return false;
    }
    return true;
}

int resipod()
{
    int c = 0,res;
    for(int i = 0;i<s.size();i++)
    {
        cnt[s[i]-'a']++;
        if(i < s.size()-i-1)
        {
            rem[s[s.size()-1-i] - 'a']++;
        }
        else if(i > s.size()-i-1)
        {
            rem[s[i]-'a']--;
        }
        //cout << i << " " <<s.size()-i-1 << endl;
        //testOut();
        c++;
        if(check())
        {
            //cout << "Usao " << s << endl;
            if(i < s.size()-i-1)
               s.erase(s.end()-1-i,s.end());
            else if(i > s.size()-i-1)
            {
                s.erase(s.begin(),s.end());
                return c;

            }
            //cout << "Usao2 " << s << endl;
            s.erase(s.begin(),s.begin()+i+1);

            //cout << "Usao3 " << s << endl;
            return c;
        }
    }
}

int resiok()
{
    int cnt = 0;
    for(int i = 0;i<s.size();i)
    {
        if(s[0] != s[s.size()-1])
        {
            return cnt;
        }
        else
        {
            //cout << "oUsao1 " << s << endl;
            s.erase(s.begin());
            //cout << "oUsao2 " << s << endl;
            if(s.size() != 0)
                s.erase(s.end()-1);
                //cout << "oUsao3 " << s << endl;
        }
        cnt++;
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> s;

    while(s.size() != 0 && s[0] == s[s.size()-1])
    {
        s.erase(s.begin());
        if(s.size() != 0)
            s.erase(s.end()-1);
    }
    if(s.size() == 0)
    {
        cout << 1 << endl;
        return 0;
    }
    sr = s;
    reverse(sr.begin(),sr.end());
    int res = 0;
    while(s.size() > 3)
    {
        res += resipod();
        res += resiok();
        cl();
        //cout << res << endl;
    }
    if(s.size() == 3)
        res+=2;
    int res2 = 0;
    s = sr;

    //cout << "Obrnut" << endl;
    while(s.size() > 3)
    {
        res2 += resipod();
        res2 += resiok();
        cl();
        //cout << res2 << endl;
    }
    if(s.size() == 3)
        res2+=2;
    cout << min(res,res2) << endl;

    return 0;
}