n = gets.to_i
ar = Array.new(n).map{Array.new()}
n.times {|i| ar[i] = gets.chomp.split("")}
ans = 0
check = Array.new(n,0)
count = [0,0,0]
n.times{|i|
  if ar[i][0] == "B"
    check[i] += 1
  end
  if ar[i][-1] == "A"
    check[i] += 2
  end
  if check[i] == 1
    count[0] += 1
  elsif check[i] == 2
    count[1] += 1
  elsif check[i] == 3
    count[2] += 1
  end
}
if count[0]
  inst = (count[0]-count[1]).abs
  ans += count[2]
  ans += [count[0],count[1]].min
end

for i in 0..n-1
  for j in 0..ar[i].length-1
    if ar[i][j] == "A" && j != ar[i].length-1
      if ar[i][j+1] == "B"
        ans += 1
      end
    end
  end
end
puts ans
