n = gets.to_i
s_array = n.times.map{gets.chomp}
first_b = 0
last_a = 0
cnt = 0
s_array.each do|s|
  (0..s.size-2).each do|i|
    if s.slice(i,2) == "AB"
      cnt += 1
    end
  end
  last_a += 1 if s[-1] == "A"
  first_b += 1 if s[0] == "B"
end

puts cnt + [last_a,first_b].min