using System;
using System.Linq;
using System.Diagnostics;

namespace Palindrom_šafl
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            if (s.SequenceEqual(s.Reverse()))
            {
                Console.WriteLine("1");
            }
            else
            {
                Console.WriteLine(brojac(s));
            }
        }
        static int brojac(string str)
        {
            int n = str.Length;
            int br=0;
            char []s=str.ToCharArray();
            for (int i = 0; i < n/2; i++)
            {
                int l = i;
                int d = n - l - 1;
                while (l<d)
                {
                    if (s[l] == s[d])
                        break;
                    else
                        d--;
                }
                if (l == d)
                    return -1;
                else
                {
                    for (int j = d; j < n - l - 1; j++)
                    {
                        char t = s[j];
                        s[j] = s[j + 1];
                        s[j + 1] = t;
                        br++;
                    }
                }
            }
            return br;
        }
    }
}