n = gets.chomp.to_i

count = 0
begin_b_count = 0
end_a_count = 0
begin_b_end_a_count = 0
n.times do
  str = gets.chomp
  count += str.scan(/AB/).size
  begin_b_count += 1 if str[0] == 'B'
  end_a_count += 1 if str[-1] == 'A'
  begin_b_end_a_count += 1 if str[0] == 'B' && str[-1] == 'A'
end

if end_a_count > 0 && end_a_count == begin_b_count && end_a_count == begin_b_end_a_count
  count -= 1
end

puts count + [begin_b_count, end_a_count].min
