#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int n;int a=0,b=0,ab=0;int count=0;
	string ss;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>ss;
		int len=ss.length();
		if(ss[0]=='B') b++;
		if(ss[len-1]=='A') a++;
		if(ss[0]=='B'&&ss[len-1]=='A') ab++;
		for(int j=1;j<len;j++)
		{
			if(ss[j]=='B'&&ss[j-1]=='A')count++;
		}
	}
	if(a==b&&b==ab&&ab!=0) count--;
	cout<<count+min(a,b)<<endl;
	return 0;
}