def find_ab(str)
    return str.include?('A') || str.include?('B')
end

N = (gets).to_i
strs = []
N.times do
    strs << gets.strip.gsub(/[^AB]+/, "-")
end
strs.select! { |a| (a.length > 0) && find_ab(a) }
#puts strs
strs.sort!

state = false # falseのときAで終わるひとを探す、tureのときBで始まる人を探す
isLoop = true
ret_str = ""
while isLoop
    isLoop = !state # stateがfalseのときは抜けないようにする
    strs.each.with_index do |str, i|
        if state then
            if str=~/^B/ then
                ret_str << str
                #puts "^B : " + str
                strs.delete_at(i)
                isLoop = true
                break # 一度抜ける
            end
        else
            if str=~/A$/ then
                ret_str << str
                #puts "A$ : " + str
                strs.delete_at(i)
                isLoop = true
                break
            end
        end
    end
    state = !state
end
# あまったやつはくっつけておく
strs.each {|s| ret_str << s}

#puts ret_str

count = 0
index = -1
while true
    index = ret_str.index("AB", index+1)
    break if index.nil?
    count += 1
end

puts count
