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

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

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

  count += str.scan("AB").size
end

count+=[a, b,n-1].min
if lim && [a,b,n-1].min == n-1
  count -=1
end
puts count