#define _GLIBCXX_DEBUG #import using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i < (int)(n); i++) typedef long long ll; int main() { int a;string s;cin>>a>>s;int res = a-1;int base = 0; rep(i,a-1){ if(s[i]=='B'&&s[i+1]=='B'){res--;base = 1;} } rep(i,a-2){ if(s[i]=='B'&&s[i+1]=='A'&&s[i+2]=='B'){res--;} } cout << res+base << endl; }