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

    var bStart = 0
    var aEnd = 0
    var both = 0
    var cnt = 0

    val regex = "(AB)".toRegex()

    repeat(n) {
        val s = readLine()!!
        cnt += regex.findAll(s).count()
        if (s[0] == 'B' && s[s.length-1] == 'A') {
            both++
        } else if (s[0] == 'B') {
            bStart++
        } else if (s[s.length-1] == 'A') {
            aEnd++
        }
    }

    if (both == 0) {
        cnt += Math.min(bStart, aEnd)
    } else {
        if (bStart + aEnd > 0) {
            cnt += Math.min(bStart, aEnd) + both
        } else {
            cnt += Math.max(both - 1, 0)
        }
    }

    println(cnt)
}