n = gets().split().map(&:to_i)[0]

c = 0
ea = 0
bb = 0

for i in 1..n
  t = gets().chomp().gsub("AB", "-")
  c += t.count("-")
  if t[0] == "B"
    bb += 1
  end
  if t[-1] == "A"
    ea += 1
  end
end

c += [bb, ea, n - 1].min

puts c