local N = io.read("n", "l")
local inner = 0
local endsA = 0 -- but not starts w/ B
local startsB = 0 -- but not ends w/ A
local both = 0
for i=1, N do
    local s = io.read("l")
    local head = string.sub(s, 1, 1)
    local tail = string.sub(s, #s, #s)
    if head == 'B' and tail == 'A' then
        both = both + 1
    elseif head == 'B' then
        startsB = startsB + 1
    elseif tail == 'A' then
        endsA = endsA + 1
    end
    for _ in string.gmatch(s, "AB") do
        inner = inner + 1
    end
end
local ans = inner
if both > 0 then
    ans = ans + both - 1
    if endsA > 0 then
        ans = ans + 1
        endsA = endsA - 1
    end
    if startsB > 0 then
        ans = ans + 1
        startsB = startsB - 1
    end
end
ans = ans + math.min(endsA, startsB)
print(ans)