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

c = 0
ea = 0
bb = 0
bo = 0

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

a = [bb, ea].min
if a == bo
  c += a - 1
else
  c += a
end

puts c