n = gets.chomp.to_i
cnt = 0
cnt_b = 0
cnt_a = 0
cnt_ba = 0
s = []
n.times do |i|
  s[i] = gets.chomp
  (s[i].length-1).times do |j|
    if s[i][j] == "A"
      cnt += 1 if s[i][j+1] == "B"
    end
  end
  if s[i][0] == "B" && s[i][-1] == "A"
    cnt_ba += 1
  end
  if s[i][0] == "B"
    cnt_b += 1
  end
  if s[i][-1] == "A"
    cnt_a += 1
  end
end
if [cnt_b, cnt_a].max == cnt_ba && cnt_ba > 0
  cnt += [cnt_b, cnt_a].min - 1
else
  cnt += [cnt_b, cnt_a].min
end
puts cnt
