n=gets.chomp.to_i
s=[]
n.times do
  s.push(gets.chomp)
end
ed_a=0
ft_b=0
count=0
for i in 0..n-1 do
  slen=s[i].length
  ed_a+=1 if s[i][slen-1]=="A"
  ft_b+=1 if s[i][0]=="B"
  for cha in 0..slen-2
    count+=1 if s[i][cha]=="A" && s[i][cha+1]=="B"
  end
end
count+= ed_a < ft_b ? ed_a : ft_b
puts count
