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

int main() {
	string s;
    cin>>s;
    int n = s.size();
    unordered_map<int,int> k; 
    int cnt = 0;
    for(int i=0;i<=n-1;i++){
    if(s[i]=='B'){
        cnt++;
        k[i]++;
    }
   }
     int ans = 0;
    
    for(int i = 0 ;i < s.size();i++){
     int com = 0;
      if(n%2 == 0){
         for(int i = 0 ; i < n ;i = i+2){
             if(k[i] == 'B')com++;
         }

           for(int i = 1 ; i < n ;i = i+2){
             if(k[i] == 'B')com++;
         }
         ans = n/2 - com; 
        }else if(n%2 == 1){
         if(cnt == n/2){
           for(int i = 1 ; i < n ;i = i+2){
             if(k[i] == 'B')com++;
         }
         ans = n/2 - com; 
         }else if(cnt == (n/2+1)){
          for(int i = 0 ; i < n ;i = i+2){
             if(k[i] == 'B')com++;
         }
          ans = n/2 - com;
         }
     }else cout<<-1;
    }
   cout<<ans;      
}


