##templete
n = gets.chomp.to_i
strings = []
n.times do
  strings.push(gets.chomp)
end

innerAB = 0

for str in strings do
  index = 0
  while index < str.length - 1 do
    if str[index] == 'A'
      if str[index + 1] == 'B'
        innerAB += 1
        index += 2
      end
    end
    index += 1
  end
end


headB = 0
tailA = 0
sameAB = 0

for str in strings do
  if str[0] == "B" && str[-1] == "A"
    sameAB += 1
  elsif str[0] == "B"
    headB += 1
  elsif str[-1] == "A"
    tailA += 1
  end
end

ans = [sameAB - 1, 0].max
sameAB = 1

if headB > tailA
  ans += tailA
  headB -= tailA
  ans += [headB, sameAB].min
else
  ans += headB
  tailA -= headB
  ans += [tailA, sameAB].min
end

puts ans + innerAB
