#include <bits/stdc++.h>
using namespace std;
int widget(list<int>& lst, int beginN) {
  int editN = beginN;
  while (lst.size() != 1) {
    int first = lst.front();
    int flag = 0;
    for (auto x : lst) {
      if (x != first) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      return editN;
    }
    editN += 2;
    int f = lst.front();
    int b = lst.back();
    while (lst.front() == f) {
      lst.pop_front();
    }
    while (lst.back() == b) {
      lst.pop_back();
    }
  }
  return editN;
}
int main() {
  string S;
  cin >> S;
  list<int> lst;
  int begin_b_flag;
  int begin_w_flag;
  for (auto itr : S) {
    if (itr == 'B') {
      lst.push_back(0);
      begin_b_flag = 1;
    } else {
      lst.push_back(1);
      begin_w_flag = 1;
    }
  }
  int res = 0;
  if (begin_b_flag == 0 || begin_w_flag == 0) {
    cout << 0 << "\n";
    return 0;
  } else if (lst.front() != lst.back()) {
    while (lst.back() != lst.front()) {
      lst.pop_back();
    }
    res = widget(lst, 1);
  } else {
    res = widget(lst, 0);
  }
  cout << res << endl;
}
