program prob3
    implicit none
    integer::N, i, l, ans, a, b, c, j
    character(len=10)::s

    ans = 0
    a = 0
    b = 0
    c = 0
    read(*,*) N
    do j = 1, N
        read(*,*) s
        l = len_trim(s)
        do i = 1, l-1
            if(s(i:i) .eq. "A" .and. s(i+1:i+1) .eq. "B") then
                ans = ans + 1
            end if
        end do
        if(s(1:1) .eq. "B")then
            b = b+1
            if(s(l:l) .eq. "A")then
                c = c+1
            end if
        end if
        if(s(l:l) .eq. "A")then
            a = a+1
        end if
    end do
    ans = ans + min(a,b)
    if(a==c .and. b==c .and. a>0)then
        ans = ans - 1
    end if
    write(*,*) ans

    stop
end program