#include <bits/stdc++.h>
using namespace std;
long long brojac=0;
int funkcija(string s)
{
    for (int i=0;i<s.length()/2;i++)
	{
        int left=i;
        int right=s.length()-left-1;
        while (left<right)
		{
            if (s[left]==s[right])
			{
                break;
            }
            else
			{
                right--;
            }
        }
        if (left == right)
		{
            return -1;
        }
        for (int j=right;j<s.length()-left-1;j++) 
		{
            swap(s[j],s[j+1]);
            brojac++;
        }
    }
    if(brojac==0) brojac=1;
    return brojac;
}
  
int main()
{
    string s;
    cin>>s;
    int x1=funkcija(s);
    reverse(s.begin(), s.end());
    int x2=funkcija(s);
    cout << max(x1, x2);
    return 0;
}