import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

int readInt(){
  return readln.chomp.to!int;
}

int[] readInts(){
  return readln.chomp.split.to!(int[]);
}

void main(){
  int n = readInt();
  string[] str = new string[n];

  foreach(ref s; str) s = readln.chomp;
  int ret, frontB, endA;
  bool both = false;

  foreach(s; str){
    ret += count(s, "AB");
    if(s[0] == 'B' && s[$-1] == 'A') both = true;
    if(s[0] == 'B') frontB++;
    if(s[$-1] == 'A') endA++;
  }

  ret += min(frontB, endA);
  if(frontB == endA && both) ret--;
  writeln(ret);
}