import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val sn = Iterator.continually(in.readLine).take(n).toArray

  val tar = "AB"
  var sum1 = sn.map(_.sliding(2).count(_ == tar)).sum

  val b_ = sn.count(s => s.head == 'B' && s.last != 'A')
  val _a = sn.count(s => s.head != 'B' && s.last == 'A')
  val ba = sn.count(s => s.head == 'B' && s.last == 'A')

  val sum2 = ba match {
    case x if x == 0 => _a min b_
    case x if _a + b_ == 0 => ba - 1
    case _ => ba + (_a min b_)
  }
  // debug(sum1, ba, b_, _a)

  val ans = sum1 + sum2
  println(ans)

  def debug(any:Any*):Unit = {
    if(this.getClass.toString != "class Main$")
      println(any.mkString(" "))
  }
}