


#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


S.each do |s|
  if s[0]=='B'
    startwithB+=1
  end
  if 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

catAB=[startwithB,endwithA,S.size-1].min

puts catAB+internalAB