program main
   implicit none
   integer::n,i,counter=0,j,acounter=0,bcounter=0,abcounter=0
   character(10) s(10000)
   read(*,*)n
   do i=1,n
      read(*,*)s(i)
   enddo
   do i=1,n
      if(s(i)(1:1)=="B")bcounter=bcounter+1
      do j=2,len_trim(s(i))
         if(s(i)(j-1:j-1)=="A".and.s(i)(j:j)=="B")counter=counter+1
      enddo
      if(s(i)(len_trim(s(i)):len_trim(s(i)))=="A")acounter=acounter+1
      if(s(i)(len_trim(s(i)):len_trim(s(i)))=="A".and.s(i)(1:1)=="B")abcounter=abcounter+1
   enddo
   counter=counter+min(acounter,bcounter)
  if(abcounter==acounter.and.abcounter==bcounter)counter=counter-min(1,abcounter)
   write(*,*)counter
end program main
