def min(a,b)
    a < b ? a : b
end

n=gets.to_i
s=n.times.map{gets.chomp.chars}

cnt=0
x,y,z=0,0,0
n.times do |i|
    x += 1 if s[i][-1] == 'A' && s[i][0] != 'B'
    y += 1 if s[i][-1] != 'A' && s[i][0] == 'B'
    z += 1 if s[i][-1] == 'A' && s[i][0] == 'B'
    (s[i].size-1).times do |j|
        cnt += 1 if s[i][j] == 'A' && s[i][j+1] == 'B'
    end
end
m = min(x,y)
t = z
if z == 0
    t = m
else
    if x+y == 0
        t -= 1
    else
        t += m
    end
end

puts t + cnt
