n = gets.to_i
sum = 0
ba_sum = 0
b_sum = 0
a_sum = 0
for i in 0...n do
  s = gets.chomp
  b = (s[0] == "B")
  a = (s[-1] == "A")
  if b && a
    ba_sum += 1
  elsif b
    b_sum += 1
  elsif a
    a_sum += 1
  end
  cnt = 0
  while !s.sub!(/AB/, "").nil?
    cnt += 1
  end
  sum += cnt
end
if ba_sum >= 1
  sum += ba_sum - 1
  if b_sum >= 1
    sum += 1
    b_sum -= 1
  end
  if a_sum >= 1
    sum += 1
    a_sum -= 1
  end
end
sum += (b_sum < a_sum) ? b_sum : a_sum
puts sum
