#include <bits/stdc++.h>
using namespace std;
bool possible(string word) {
int a = 0;
int b = 0;
for (int i=0; i<word.size(); i++)
if (word[i] == 'a') a++;
else b++;
return !(a%2 == 1 && b%2 == 1);
}
int main() {
string word;
int compare_left, compare_right, operations = 0;
cin >> word;
if (possible(word) == 0)
cout << "-1";
else {
int left = 0, right = word.size()-1;
while (left < right) {
if (word[left] != word[right]) {
operations++;
compare_left = left + 1; compare_right = right - 1;
while (word[left] == word[compare_left] && word[right] == word[compare_right]) {
compare_left++; compare_right--;
operations++;
}
if (word[compare_left] != word[left])
word[compare_left] = word[left];
else
word[compare_right] = word[right];
}
left++; right--;
}
cout << operations;
}
}