# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_c

n = gets.to_i
res = 0

lefts = []
rights = []
words = []

n.times do
  word = gets.chomp
  res += word.scan('AB').size
  if word[0] == 'B'
    rights << word
  end
  if word[-1] == 'A'
    lefts << word
  end
  words << word
end

res += [lefts.size, rights.size].min
puts res