#N=gets.to_i
#S=gets.chomp
#A=(0...N).map{gets.to_i}
#sum=A.inject(&:+)
#B=gets.split.map(&:to_i)
N=gets.to_i
 
 
S=(0...N).map{gets.chomp}
 
internalAB=0
endwithA=0
startwithB=0
startwithBendwithA=0
 
S.each do |s|
  if s[0]=='B'
    if s[-1]=='A'
      startwithBendwithA+=1
    else
      startwithB+=1
    end
  elsif s[-1]=='A'
    endwithA+=1
  end
  lastisA=false
  s.each_char do |c|
    if c=='A'
      lastisA=true
      next
    elsif lastisA && c=='B'
      internalAB+=1
    end
    lastisA=false
  end
end

if startwithBendwithA>=1 && startwithB==0 && endwithA==0
  catAB=startwithBendwithA-1
else
  catAB=startwithBendwithA+[startwithB,endwithA].min
end

puts catAB+internalAB