let N = Int(readLine()!)!
var ans = 0
var aCount = 0
var bCount = 0
var abCount = 0
for _ in 0..<N {
  var str = readLine()!.characters.map{String($0)}
  var len = str.count
  let hasA = str[len-1] == "A"
  let hasB = str[0] == "B"
  if hasA && hasB {
    abCount += 1
  } else {
    if hasA {
      aCount += 1
    }
    if hasB {
      bCount += 1
    }
  }
  for i in 1..<len {
    if str[i-1] == "A" && str[i] == "B" {
      ans += 1
    }
  }
}
if aCount + bCount > 0 {
  ans += min(aCount, bCount) + abCount
} else {
  ans += abCount - 1
}
print(ans)