#include <iostream>
using namespace std;

int sua, sbu, sba, n, ans;
string s;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		for (int j = 1; j < s.size(); j++)
			ans += (s[j - 1] == 'A' && s[j] == 'B');
		if (s[0] == 'B' && s.back() == 'A')
			sba++;
		else if (s[0] == 'B')
			sbu++;
		else if (s.back() == 'A')
			sua++;
	}
	if (sua > 0)
		ans += sba + min(sua, sbu);
	else if (sba > 0)
		ans += sba - 1 + (sbu > 0);
	cout << ans;
}