/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
using namespace std;
char s[1005];
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
while(scanf("%s", s) == 1){
int len = strlen(s);
stack<char>st;
for (int i = 0; i < len; i++){
if(s[i] == 'B'){
printf("%d\n", (int)st.size());
break;
}else if(s[i] == '('){
st.push('(');
}else{
st.pop();
}
}
}
return 0;
}
/**/