program sample
  implicit none
  integer :: n,i,smax,ans
  integer,allocatable :: a(:),b(:)
  character(100) :: s
  allocate(a(n))
  allocate(b(n))
  read(*,*) n
  read(*,*) s

  do i=1,n
     if(s(i:i)=='W')then
        a(i)=-1
     else
        a(i)=1
     endif
  enddo

  write(*,*) a

  do i=1,n
     b(i)=sum(a(1:i-1))-sum(a(i+1:n))
  enddo
  
  smax=maxval(b)
  ans=((n-1)-smax)/2

  write(*,*) ans

  
end program sample