n = gets.chomp.to_i
s = []
for i in 1..n do
    s.push(gets.chomp)
end

startB = 0
endA = 0
isBstart = false
wordBA = 0
cnt = 0
for i in 1..n do
    isBstart = false
    if s[i-1].match(/^B/)
        startB += 1
        isBstart = true
    end
    if s[i-1].match(/A$/)
        endA += 1
        if isBstart 
            wordBA += 1
        end
    end
    cnt += s[i-1].scan("AB").size
end

if startB == wordBA and endA == wordBA 
    cnt += wordBA -1
else
    cnt += [startB,endA].min
end

p cnt