#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) template inline bool chmax(T&a,T b){if(a inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;} using ll = long long; int n; string s; int main () { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> s; int ans=0, bb=0; rep(i,n-1) s.substr(i,2)!="BB" ? ans++ : bb=1; rep(i,n-2)if(s.substr(i,3)=="BAB") ans--; ans+=bb; cout << ans << '\n'; return 0; }