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

n = gets.to_i
res = 0

def is_left(word)
  word[0] != 'A' && word[-1] == 'B'
end

def is_mid(word)
  word[0] == 'B' && word[-1] == 'A'
end

def is_right(word)
  word[0] == 'B' && word[-1] != 'A'
end


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

n.times do
  word = gets.chomp
  res += word.scan('AB').size
  if is_left(word)
    lefts << word
  elsif is_mid(word)
    mids << word
  elsif is_right(word)
    rights << word
  end
  words << word
end

minsize = [lefts.size, rights.size].min


if minsize > mids.size
  res += mids.size + 1
  res += minsize - mids.size
elsif mids.size >= minsize
  res += mids.size + 1
end
puts res