n = $stdin.gets.to_i
ary = []
result = 0
a = 0
b = 0

n.times do |i|
  s = $stdin.gets
  ary[i] = s
  if s[0] == 'B'
    b += 1
  end
  if s[-2] == 'A'
    a += 1
  end
  result += ary[i].scan("AB").size
end

puts result + [a,b].min
