n = $stdin.gets.to_i
ary = []
result = 0
a = 0
b = 0
docchimo = 0
lk=false
n.times do |i|
  s = $stdin.gets
  ary[i] = s
  if s[0] == 'B'
    b += 1
  end
  if s[-2] == 'A'
    a += 1
  end
  if s[0] == 'B' && s[-2] == 'A'
    docchimo += 1
  end

  if s[0] != 'B' && s[-2] == 'A'
    lk=true
  end

  result += ary[i].scan("AB").size
end


if docchimo > 0 && a==b && docchimo == a
  result -=1
end
puts result + [a,b].min