n=gets.to_i
ab_count=0
b_front=0
a_tail=0
bf_at=0
n.times do|i|
	str=gets.chomp
	ab_count+=str.scan("AB").length
	if(str[str.length-1]=="A")
		if(str[0]=="B")
			bf_at+=1	
		else
			a_tail+=1
		end
	elsif(str[0]=="B")
		b_front+=1
	end
end
if(bf_at>0 and a_tail>0)
	bf_at-=1
	a_tail-=1
	ab_count+=1
end
ab_count+=bf_at
if(b_front>0)
	ab_count+=1
	b_front-=1
end
if a_tail>b_front
	ab_count+=b_front
else
	ab_count+=a_tail
end
puts ab_count
