program ARC098C
    implicit none
    integer(8)::N,i
    integer(8)::e_count=0
    integer(8)::w_count=0
    integer(8)::result
    integer(8),allocatable,dimension(:)::E,W
    character(300000)::S

    read(5,*)N
    read(5,*)S
    allocate(E(N))
    allocate(W(N))
    result=N-1

    do i=1,N
        if(S(i:i)=='E')then
            e_count=e_count+1
        else
            w_count=w_count+1
        end if
        E(i)=e_count
        W(i)=w_count
    end do

    do i=1,N
        if(i==1)then
            if(E(N)-E(i)<result)then
                result=E(N)-E(i)
            end if
        else if(i<N)then
            if(W(i-1)+E(N)-E(i)<result)then
                result=W(i-1)+E(N)-E(i)
            end if
        else if(W(i-1)<result)then
            result=W(i-1)
        end if
    end do

    print'(i0)',result
end program ARC098C