n = gets.chomp.to_i
b_a = 0
b_x = 0
x_a = 0
default = 0
n.times do |i|
  str = gets.chomp
  if (str[0] == 'B' && str[-1] == 'A')
    b_a += 1
  elsif(str[0] == 'B')
    b_x += 1
  elsif(str[-1] == 'A')
    x_a += 1
  end
  default += str.scan('AB').length
end
hoge = [b_x,x_a].min
fuga = [b_x,x_a].max

if ((fuga-hoge) >= b_a)
  puts default + hoge + b_a
else
  puts default + hoge + (fuga-hoge) + (b_a / 2)
end