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
    h[0] += 1
    h[1] += 1
    c += h[2] - 1
end

puts c + [h[0], h[1]].min