fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val s = Array(N) { readLine()!! }

    val a = s.indices.filter { s[it].last() == 'A' }
    val b = s.indices.filter { s[it].first() == 'B' }
    val ab = s.indices.filter { s[it].first() == 'B' && s[it].last() == 'A' }

    var r = s.map {
        var t = 0
        for (i in 0 .. it.length - 2) {
            if (it.substring(i, i + 2) == "AB") {
                t++
            }
        }
        t
    }.sum()

    if (ab.isNotEmpty() && ab.size == a.size && ab.size == b.size) {
        r += ab.size - 1
    } else {
        r += Math.min(a.size, b.size)
    }

    println(r)
}
