"use strict";
function Main(input) {
  const args = input.split('\n');
  const N = parseInt(args.shift());
  let count = 0;
  let countA = 0;
  let countB = 0;
  args.forEach(f => {
    count += (f.length - f.replace('AB', '').length) / 2;
    if (f.charAt(0) === 'B') {
      countB ++;
    }
    if (f.charAt(f.length - 1) === 'A') {
      countA ++;
    }
  });
  count += countA < countB ? countA : countB;
  console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));