n=gets.to_i
array=[]
n.times{
    array.push(gets.chomp.split(''))
}

ans=0
righta=0
leftb=0

array.map{|str|
    
    str.map.with_index{ |char,index|
       if str[index+1] && str[index]=="A" && str[index+1]=="B"
           ans+=1
       end
    }
    
    if str[0]=="B"
        leftb+=1
    end
    
    if str[-1]=="A"
        righta+=1
    end
}

puts ans+[leftb,righta].min