n=gets.chomp.to_i
s=Array.new
count=0
a,b,ab=0,0,0

for i in 0..n-1
  s[i]=gets.chomp
  count+=s[i].scan(/AB/).size

  if s[i][s[i].size-1]=="A" && s[i][0]=="B"
    ab+=1
  elsif s[i][0]=="B"
    b+=1
  elsif s[i][s[i].size-1]=="A"
    a+=1
  end
end
ab-=1 if ab>0
p count+[a,b].min+ab