fun main(args:Array<String>){
    val n=readLine()!!.toInt()
    val s=Array(n){ readLine()!!}
    val a=s.indices.filter{s[it].last()=='A'}
    val b=s.indices.filter{s[it].first()=='B'}
    val ab=s.indices.filter{s[it].first()=='B'&&s[it].last()=='A'}
    var ans=0
    for(t in s){
        for(i in 0..t.length-2) {
            ans += if (t.slice(i..i + 1) == "AB") 1 else 0
        }
    }
    if(ab==a&&ab==b&&ab.size>0){
        println(ans+Math.min(a.size,b.size)-1)
    }
    else{
        println(ans+Math.min(a.size,b.size))
    }
}
