n = gets.chomp.to_i
a = Array.new(n)
cnt = 0
a_hi = 0
b_hi = 0
ab_hi = 0
n.times {|i|
  a[i] = gets.chomp
  a[i].each_char.with_index do |a_char,k|
    if a_char == 'A' and a[i][k+1] == 'B'
      cnt += 1
    end
  end
  if a[i][0] == 'B' and a[i][-1] == 'A'
    ab_hi += 1
  elsif a[i][0] == 'B'
    b_hi += 1
  elsif a[i][-1] == 'A'
    a_hi += 1
  end
}
if ab_hi >= 2
  cnt += ab_hi - 1
  ab_hi = 1
end
amari = (a_hi - b_hi).abs
cnt += [a_hi,b_hi].min + [ab_hi,amari].min

puts cnt 
