local counter=0
local BA,B_,_A=0,0,0
local n=io.read("n","l")
for i=1,n do
    local s=io.read()
    local _,sAB=s:gsub("AB","")
    counter=counter+sAB
    sf=s:sub(1,1)
    sl=s:sub(#s,#s)
    BA=((sf=="B" and sl=="A") and BA+1 or BA)
    B_=((sf=="B" and sl~="A") and B_+1 or B_)
    _A=((sf~="B" and sl=="A") and _A+1 or _A)
end

if BA==0 then
    counter=counter+math.min(B_,_A)
elseif BA>0 and B_+_A>0 then
    counter=counter+BA+math.min(B_,_A)
elseif BA>0 and B_+_A==0 then
    counter=counter+BA-1
end
print(counter)