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

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

cnt=0
last_a=0
first_b=0
n.times do |i|
    last_a += 1 if s[i][-1] == 'A'
    first_b += 1 if 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

puts min(last_a,first_b) + cnt
