n = gets.chomp.to_i
s = n.times.map {|i| gets.chomp }

ab_cnt = tail_a_cnt = head_b_cnt = both_cnt = 0
s.each do |l|
  ab_cnt += l.scan("AB").size
  tail_a_cnt += 1 if l.end_with?("A")
  head_b_cnt += 1 if l.start_with?("B")
  both_cnt += 1 if l.end_with?("A") && l.start_with?("B")
end

if tail_a_cnt == both_cnt && head_b_cnt == both_cnt
  puts ab_cnt + both_cnt - 1
else
  puts ab_cnt + [tail_a_cnt, head_b_cnt].min
end
