fun main(args: Array<String>) {
    val N=readLine()!!.toInt()
    val s =Array(N){ readLine()!! }
    var ab=0
    var a=0
    var b=0
    var ba=0
    s.forEach {
        it.forEachIndexed { i,c1->if(i<it.length-1&&c1=='A'&&it[i+1]=='B')ab+=1 }
        if(it[0]=='B'){
            if(it[it.length-1]=='A')ba+=1
            else b+=1
        }else if(it[it.length-1]=='A')a+=1
    }
    var abab=Math.min(ba,Math.min(a,b))
    ba-=abab
    a-=abab
    b-=abab
    var tba=0
    if(ba>0){
        if(abab>0)tba=ba
        else {
            tba=ba-1
            if(Math.max(a,b)>0)tba+=1
        }
    }else{
        tba=Math.min(a,b)
    }
    print(ab+abab*2+tba)
}