n = gets.rstrip.to_i

ans = 0
first = 0
last = 0
double = 0

n.times do
  s = gets.rstrip
  ans += s.scan('AB').size
  first += 1 if s[0]=='B'
  last  += 1 if s[-1]=='A'
  double+= 1  if s[0]=='B' and s[-1]=='A'
end

if double == first and double == last
  p ans + [first, last].min - 1
else
  p ans + [first, last].min
end