program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,ans
    integer(int32), allocatable:: l_s(:), r_s(:)
    character(300000):: s

    read*, n
    read*, s
    allocate(l_s(0:n),r_s(n+1))

    l_s(:) = 0
    do i=1,n
        if (s(i:i) == 'W') then
            l_s(i)=l_s(i-1)+1
        else
            l_s(i)=l_s(i-1)
        end if
    end do

    r_s(:) = 0
    do i=n,1,-1
        if (s(i:i) == 'E') then
            r_s(i) = r_s(i+1)+1
        else
            r_s(i) = r_s(i+1)
        end if
    end do

    ans=300000
    do i=1,n
        ans=min(ans, l_s(i-1)+r_s(i+1))
    end do
    print'(i0)', ans

end program name