n = gets.to_i
h = [0, 0, 0]
c = 0

n.times do
    s = gets.chomp
    c += s.scan("AB").size
    
    if s[0] == "B" && s[-1] == "A"
        h[2] += 1
    elsif s[0] == "B"
        h[1] += 1
    elsif s[-1] == "A"
        h[0] += 1
    end
end

if h[2] > 0
    c += h[2] - 1
    if h[0] > 0 && h[1] > 0
        c += 1 + (h[0] < h[1] ? h[0] : h[1])
    elsif h[0] > 0 || h[1] > 0
        c += 1
    end
else
    c += h[0] < h[1] ? h[0] : h[1]
end

puts c