program main
Implicit None
	character(len = 10),allocatable::s(:)
	integer(8)::n,i,j,p=0,x=0,y=0,z=0
	integer(8),allocatable::a(:),b(:)
	
	read*,n
	allocate(s(n),a(n),b(n))
	a = 0 ;b = 0
	
	read*,s
	
	do i = 1,n
		if(s(i)(1:1) == "B") b(i) = 1
		do j = 1,9
			if(s(i)(j:j) == " ")then
				if(s(i)(j-1:j-1) == "A") a(i) = 1
				exit
			endif
			if(s(i)(j:j+1) == "AB")then
				p = p+1
			endif
		enddo
		if(s(i)(9:10) == "A ") a(i) = 1
		if(s(i)(10:10) == "A") a(i) = 1
	enddo
	
	do i = 1,n
		if(a(i) == 1 .and. b(i) == 1) z = z+1
		if(a(i) == 1) x = x+1
		if(b(i) == 1) y = y+1
	enddo
	x = x-z
	y = y-z
	
	if(x == 0 .and. y == 0)then
		p = p+max(0,z-1)
		else if(y == 0 .or. x == 0)then
			p = p + z
		else if(z == 0)then
			p = p + min(x,y)
		else
			p = p + z + min(x,y)
	endif
	
	print*,p
end program main