N=gets.to_i
ss=$<.read.split.map(&:chomp)

a = 0
b=0
ab=0
ret = 0
ss.each do |s|
  i = -1
  ret += 1 while i = s.index('AB',i+1)
  if s[0]=='B' && s[-1]=='A'
    ab+=1
  elsif s[0]=='B'
    b+=1
  elsif s[-1]=='A'
    a+=1
  end
end

if 0 < ab
  ret += ab-1
  if 0 < a
    a -= 1
    ret += 1
  end
  if 0 < b
    b -= 1
    ret += 1
  end
end

ret += [a,b].min
puts ret
