import java.util.*
import java.math.*
fun main(args: Array<String>) {

//    var (N, K) = readLine()!!.split(" ").map { it.toInt() }
    var N = readLine()!!.toInt()
//    val D = readLine()!!.split(" ").map { it.toLong() }
//    val A = readLine()!!.split(" ").map { it.toInt() }.toIntArray()

    var ans=0
    var A = 0
    var B = 0
    var sep = false
    //ABA BA BA BA
    for (i in 0 until N) {
        val S = readLine()!!
        if (S.last() == 'A') A++
        if (S.first() == 'B') B++
        if (!sep && A != B) sep = true

        var isA = false
        for (c in S) {
            if (isA && c == 'B') ans++
            isA = c == 'A'
        }
    }
    var min = Math.min(A,B)
    if (!sep && min > 0) min--
    println(ans+min)
}
