import java.util.Arrays
import java.util.ArrayList

const val MOD: Long = (1e9+7).toLong()
fun Double.format(digits: Int) = String.format("%.${digits}f", this)

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

    var cnt = 0
    var cnta = 0
    var cntb = 0
    var cntd = 0
    var non = 0
    for (t in s) {
        for (i in 0..t.length-2) {
            cnt += if (t.slice(i..i+1) == "AB") 1 else 0
        }
        if (t.last() == 'A' && t[0] == 'B') {
            cntd += 1
        } else {
            cnta += if (t.last() == 'A') 1 else 0
            cntb += if (t[0] == 'B') 1 else 0
        }
        non += if (t.last() != 'A' && t[0] != 'B') 1 else 0
    }

    if (cnta > 0 && cntb > 0) {
        if (cntd > 0) {
            println(cnt + cntd+1 + Math.min(cnta-1, cntb-1))
        } else {
            println(cnt + Math.min(cnta, cntb))
        }
    } else if (cnta > 0 || cntb > 0) {
        if (cntd > 0) {
            println(cnt + cntd)
        } else {
            println(cnt)
        }
    } else {
        println(cnt + Math.max(cntd, 1) - 1)
    }
}
