n = gets.to_i

inps = []
res = 0
a_end = 0
b_begin = 0

def howmany_ab(s)
    before = ""
    res = 0
    s.chars do |c|
        res += 1 if before == 'A' && c == 'B'
        before = c
    end
    return res
end


n.times do
    inp =  gets.chomp
    res += howmany_ab(inp)
    a_end += 1 if inp[-1] == 'A'
    b_begin += 1 if inp[0] == 'B'
end


res += [a_end, b_begin].min

res -= 1 if a_end == b_begin && a_end > 0

puts res

