n = $stdin.gets.to_i
count = 0
a = 0
b = 0

found_header = false
n.times do
  str = $stdin.gets.strip
  if str[-1]=="A"
    a+=1
    if str[0] !="B"
      found_header = true
    end
  end

  if str[0]=="B"
    b+=1
  end

  count += str.scan("AB").size
end
add =[a, b, n].min
if !found_header
  add -= 1
end
count+= [0, add].max
puts count