n = gets.chomp.to_i
s = []
n.times do |i|
  s[i] = gets.chomp
end

ans = 0
count_Bxxx = 0
count_xxxA = 0
count_BxxA = 0
n.times do |i|
  count_Bxxx += 1 if s[i][0] == 'B'
  count_xxxA += 1 if s[i][-1] == 'A'
  count_BxxA += 1 if s[i][0] == 'B' && s[i][-1] == 'A'
  ans += s[i].scan('AB').size
end

ans += [count_Bxxx, count_xxxA].min
ans -= 1 if (count_BxxA > 0) && (count_Bxxx == count_BxxA) && (count_xxxA == count_BxxA)

puts(ans)