object Main {

    def main(args: Array[String]): Unit = {
      import scala.io.StdIn._
      val N = readLine().toInt
      val s: List[String] = (0 until N).map(_ => readLine()).toList

      var c = 0
      var lastA = 0
      var firstB = 0
      s foreach { str =>
        if (str.head == 'B')
          firstB += 1
        if (str.last == 'A')
          lastA += 1
        str.sliding(2).foreach {
          case "AB" =>
            c += 1
          case _ => // no-op
        }
      }
      c += Math.min(lastA, firstB)
      println(c)
    }

}
