N = gets.to_i
s_list = []

start_b = 0
end_a = 0
both = 0

count = 0
N.times{
	s = gets.strip
	s_list << s
	s.scan(/AB/){
		count += 1
	}
	if s[0] == "B"
		if s[-1] == "A"
			both += 1
		else
			start_b += 1
		end
	elsif s[-1] == "A"
		end_a += 1
	end
}

if both >= 1
	count += (both - 1)
	if start_b > 0
		count += 1
		start_b -= 1
	end
	if end_a > 0
		count += 1
		end_a -= 1
	end
end

count += [start_b, end_a].min

puts count
