N = gets.to_i
ss = $stdin.readlines.map(&:chomp)

ab_count, a_end_count, b_beg_count = 0, 0, 0
ss.each do |s|
  ab_count += s.scan(/AB/).length
  a_end_count += 1 if s[-1] == 'A'
  b_beg_count += 1 if s[0] == 'B'
end
 
ans = ab_count + [a_end_count, b_beg_count].min
puts ans