n = gets.to_i
s = Array.new(n) { gets.chomp }

min, max = [s.count { |e| e[-1] == 'A' && e[0] != 'B' }, s.count { |e| e[-1] != 'A' && e[0] == 'B' }].minmax
both = s.count { |e| e[-1] == 'A' && e[0] == 'B' }
count = max == 0 ? [both - 1, 0].max : min + both

s.each do |e|
  idx = -2
  count += 1 while (idx = e.index('AB', idx + 2))
end

puts count