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 sum = sn.map(_.sliding(2).count(str => {
    if(str == tar) true
    else false
  })).sum
  // println(sum)
  val a = sn.count(_.last == 'A')
  val b = sn.count(s => s.head == 'B' && s.last == 'A')
  val c = sn.count(_.head == 'B')
  val ans = if(a == b) a-1 else a min c
  println(ans)
}