inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
N = inp.shift() * 1
a = 0
b = 0
ab = 0
c = 0
for (i=0; i<N; i++) {
    s = inp[i]
    if (s[0] == 'B' && s[s.length - 1] == 'A') {
        ab += 1
    } else if (s[s.length - 1] == 'A') {
        a += 1
    } else if (s[0] == 'B') {
        b += 1
    }
    for (j=0; j<s.length-1; j++) {
        if (s[j] == 'A' && s[j+1] == 'B') {
            c++
        }
    }
}
if (b>0) {
    b--
    c += ab
    ab = 0
    if (a>0) {
        c++
        a--
    }
}
if (a>0) {
    a--
    c += ab
    ab = 0
    if (b>0) {
        c++
        b--
    }
}
c += Math.min(a,b)
console.log(c)