local ior = io.input()
local n = ior:read("*n", "*l")
local num_b_st_a_ed = 0
local num_b_st = 0
local num_a_ed = 0

local tot = 0

for i = 1, n do
  local str = ior:read()
  local len = #str
  local isfirst = true
  local bcand = false
  local adet = false
  if(str:sub(1, 1) == "B") then bcand = true end
  if(str:sub(len, len) == "A") then adet = true end
  for j = 1, len - 1 do
    if(str:sub(j, j) == "A" and str:sub(j + 1, j + 1) == "B") then
      tot = tot + 1
      -- print("FOUND")
    end
  end
  if(adet and bcand) then
    num_b_st_a_ed = num_b_st_a_ed + 1
    -- print(i, "BA")
  elseif(adet) then
    num_a_ed = num_a_ed + 1
    -- print(i, "-A")
  elseif(bcand) then
    num_b_st = num_b_st + 1
    -- print(i, "B-")
  end
end
-- print(num_a_ed, num_b_st, num_b_st_a_ed)
if(num_a_ed == 0 and num_b_st == 0) then
  if(0 < num_b_st_a_ed) then
    tot = tot + num_b_st_a_ed - 1
  end
else
  tot = tot + num_b_st_a_ed + math.min(num_a_ed, num_b_st)
end
print(tot)
