fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    var a = 0
    var b = 0
    var ab = 0
    var count = 0
    repeat(n) {
        val s = readLine() ?: return
        val f = s.first()
        val l = s.last()
        if (f == 'B' && l == 'A') {
            ab++
        } else {
            if (f == 'B') {
                b++
            } else if (l == 'A') {
                a++
            }
        }
        0.until(s.length - 1).forEach {
            if (s[it] == 'A' && s[it + 1] == 'B') {
                count++
            }
        }
    }
    if (ab > 0) {
        count += (ab - 1)
        if (a > 0 || b > 0) {
            count += Math.min(a + 1, b + 1)
        }
    } else {
        count += Math.min(a, b)
    }

    println(count.toString())
}
