fun main(args: Array<String>) {
    diverta2019c()
}

fun diverta2019c() {
    val n = readLine()!!.toInt()
    val sList = (1..n).map { readLine()!! }
    val regex = Regex("AB")

    val abCount = sList.sumBy { regex.findAll(it).count() }

    var startWithBAndEndWithA = 0
    var startWithB = 0
    var endWithA = 0

    sList.forEach {
        if (it.startsWith('B')) {
            if (it.endsWith('A')) startWithBAndEndWithA++ else startWithB++
        } else if (it.endsWith('A')) endWithA++
    }

    val answer = abCount + if (startWithBAndEndWithA == 0) {
        Math.min(startWithB, endWithA)
    } else if (Math.max(startWithB, endWithA) > 0) {
        startWithBAndEndWithA + Math.min(startWithB, endWithA)
    } else {
        startWithBAndEndWithA - 1
    }

    println(answer)
}
