#include<bits/stdc++.h>
using namespace std;
int main() {
  int N, ans=0, endA=0, beginB=0, same=0; cin >> N;
  for (int i=0; i<N; i++) {
    string S; cin >> S;
    for (int j=0; j<=S.length()-2; j++) {
      if(S[j]=='A'&&S[j+1]=='B') ans++;
    }
    if(S[0]=='B') beginB++;
    if(S[S.length()-1]=='A') endA++;
    if(S[0]=='B'&&S[S.length()-1]=='A') same++;
  }
  if(endA==beginB&&endA==same&&endA!=0) ans += endA-1;
  else ans += min(endA, beginB);
  cout << ans << "\n";
}
      