import std.stdio;
import std.string;
import std.algorithm;

void main() {
	int n;
	scanf("%d\n", &n);
	int incl, lb, ra, plb, pra;
	for(size_t i;i < n; ++i){
		auto l = readln.chomp;
		incl += l.count("AB");
		if (l[0] == 'B' && l[$-1] == 'A') {
			++lb;
			++ra;
		}
		else if (l[0] == 'B') {
			++lb;
			++plb;
		}
		else if (l[$-1] == 'A') {
			++ra;
			++pra;
		}
	}
	if (pra == 0 && plb == 0) --incl;
	write(incl + min(lb, ra));
}
