"use strict"
function main(arg) {
    arg = arg.trim().split("\n")
    var n = arg.shift()
    var data = arg
    // var count = 0
    var topB = 0
    var botA = 0
    var both = 0
    var ab = 0
    for (var i = 0; i < data.length; i++) {
        var row = data[i]
        if (row[0] === 'B' && row[row.length - 1] === 'A') {
            both++
        } else if (row[0] === 'B') {
            topB++
        } else if (row[row.length - 1] === 'A') {
            botA++
        }
        ab += row.split('AB').length - 1
    }
    // console.log([both, topB, botA, ab])
    var ans = 0
    if (both > 0) {
        ans += both - 1
        if (Math.min(topB, botA) >= 1) {
            ans += 2
            ans += Math.min(topB - 1, botA - 1)
        } else {
            if (Math.min(topB, botA) === topB) {
                topB += 1
            } else {
                botA += 1
            }
            ans += Math.min(topB, botA)
        }
    } else {
        ans += Math.min(topB, botA)
    }
    ans += ab
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
