base_answer = 0

ba = 0
bo = 0
oa = 0

$stdin.each_line.drop(1).each do |line|
  line.chomp!
  base_answer += line.scan("AB").count

  b = line[0] == 'B'
  a = line[-1] == 'A'
  if a && b
    ba += 1
  elsif a
    oa += 1
  elsif b
    bo += 1
  end
end

if ba == 0
  puts base_answer + [oa, bo].min
else
  ba_answer = (oa > 0 ? 1 : 0) + (ba - 1) + (bo > 0 ? 1 : 0)
  rest_oa_bo_answer = [[oa - 1, bo - 1].min, 0].max

  puts base_answer + ba_answer + rest_oa_bo_answer
end
