N = gets.to_i
S = N.times.map { gets.chomp }

ans = 0

S.each do |s|
  l = s.size

  0.upto(l - 2) do |i|
    ans += 1 if s[i..(i + 1)] == 'AB'
  end
end

acnt = S.count { |s| s[-1] == 'A' && s[0] != 'B' }
bcnt = S.count { |s| s[0] == 'B' && s[-1] != 'A' }
ccnt = S.count { |s| s[0] == 'B' && s[-1] == 'A' }

rcnt = [acnt, bcnt].min
ans += rcnt

acnt -= rcnt
bcnt -= rcnt

ncnt = [acnt, ccnt].min
ans += ncnt
ccnt -= ncnt

mcnt = [bcnt, ccnt].min
ans += mcnt
ccnt -= mcnt

if ncnt > 0 || mcnt > 0
  ans += ccnt
else
  ans += [0, ccnt - 1].max
end

puts ans
