#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n,a,b,ans;
int fa=0,fb=0;
signed main(){
	cin>>n;
	rep(i,n){
		string s;
		cin>>s;
		rep(j,s.size()-1){
			if(s[j]=='A'&&s[j+1]=='B')ans++;
		}
		int cnt=0;
		if(s[0]=='B'){
			b++;
			cnt++;
		}
		if(s[s.size()-1]=='A'){
			a++;
			cnt++;
		}
		if(cnt==1)fb=1;
		if(cnt==2)fa=1;
	}
	
	if((fa&&!fb)||min(a,b)==n)ans--;
	cout<<min(a,b)+ans<<endl;
	return 0;
}
