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

bool provera(string s)
{
    int n = s.length();
    map<char,int> m;
    for(auto i:s)
    {
        m[i]++;
    }
    int cnt = 0;
    for(auto i = m.begin(); i!=m.end(); i++)
    {
        if(i->second%2)
        {
            cnt++;
        }
    }
    if(n%2 && cnt == 1){return true;}
    if(!(n%2) && cnt == 0){return true;}
    return false;
}

bool jePalindrom(string s){
    for(int i = 0; i <= s.length()-1; i++){
        if(s[i] != s[s.length()-1-i]){
            return false;
        }else {
            return true;
        }
    }
}

int main()
{
    string a;
    cin>>a;
    if(a[0] == '0')
    {
        return 0;
    }
    string s;
    s = a;
    int n = s.length();
    int cnt = 0;
    bool ini = false;
    if(n%2){ini = true;}
    if(provera(s))
    {
        for(int i = 0;i < n/2; i++)
        {
            bool fl = false;
            int j = 0;
            for(j = n-1-i; j > i; j--)
            {

                if(s[j] == s[i])
                {
                    fl = true;
                    for(int k = j; k < n-1-i; k++)
                    {
                        swap(s[k], s[k+1]);
                        cnt++;
                    }
                    break;
                }
            }
            if(!fl&&ini)
            {
                for(int k = i; k < n/2; k++)
                {
                    swap(s[k], s[k+1]);
                    cnt++;
                }
            }
        }
            if(cnt > 0)
                cout<<cnt<<endl;
            else if(jePalindrom(a))
                cout<<"1"<<endl;
    }
    else{
        cout<<"Nemoguce"<<endl;
    }
}