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

n.times do
  str = $stdin.gets.strip
  if str[-1]=="A"
    a+=1
  end

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

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

count+=[a, b,n-1].min
puts count
