fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val segments = Array(n, { readLine()!! })
  val baseCount = segments.sumBy { countAB(it) }
  val endsAList = (0 until n).filter { segments[it].last() == 'A' }
  val startsBList = (0 until n).filter { segments[it][0] == 'B' }
  var bonus = Math.min(endsAList.size, startsBList.size)
  if (bonus > 0 && endsAList == startsBList) {
    bonus--
  }
  println(baseCount + bonus)
}

fun countAB(s: String): Int {
  var count = 0
  for (i in 0 until s.length - 1) {
    if (s[i] == 'A' && s[i + 1] == 'B') {
      count++
    }
  }
  return count
}