N = gets.to_i
cnt = 0
dual = 0
startB = 0
endA = 0
S = []
(0...N).each do |i|
  S  << gets.chop.to_s
  cnt += S[i].scan("AB").length
  if S[i].start_with?("B") && S[i].end_with?("A")
    dual += 1
  end
  if S[i].start_with?("B")
    startB += 1
  end
  if S[i].end_with?("A")
    endA += 1
  end
end
if [startB , endA].min == N
  cnt += N-1
elsif dual > [startB , endA].min
  cnt += [startB , endA].min - 1
else
  cnt += [startB , endA].min
end
p cnt