n = gets.chomp.to_i
s = []
n.times do
  s.push gets.chomp
end
count_a = 0
count_b = 0
count_ab = 0
count_ba = 0
s.each do |e|
  count_a += 1 if e[-1] == 'A'
  count_b += 1 if e[0] == 'B'
  count_ba += 1 if e[0] == 'B' && e[-1] == 'A'
  1.upto(e.size - 1) do |i|
    count_ab += 1 if e[i - 1] == 'A' && e[i] == 'B'
  end
end
count_a -= [count_ba, count_a].min
count_b -= [count_ba, count_b].min
count = 0
if count_ba >= 1
  count = count_ab + count_ba - 1 + [count_a, 1].min + [count_b, 1].min
  count_a -= [1, count_a].min
  count_b -= [1, count_b].min
  count += [count_a, count_b].min
else
  count = count_ab + [count_a, count_b].min
end
puts count
