N = int(eval(input()))

S = eval(input())



W_cnt_array = [0] * N

E_cnt_array = [0] * N



W_cnt = 0

E_cnt = 0

for i in range(N):

    if S[i] == 'W':

        W_cnt += 1

    elif S[i] == 'E':

        E_cnt += 1

    W_cnt_array[i] = W_cnt

    E_cnt_array[i] = E_cnt



prev_dir = S[0]

num = min(max(E_cnt_array), max(W_cnt_array))

for i in range(1, N):

    if prev_dir == 'E' and S[i] == 'W':

        num = min(num, W_cnt_array[i - 1] + E_cnt_array[-1] - E_cnt_array[i])

    prev_dir = S[i]

print(num)

N = int(eval(input()))

S = eval(input())



cost = S.count('E')



ans = N

for c in S:

    if c == 'E':

        cost -= 1

    else:

        if ans > cost:

            ans = cost

        cost += 1

else:

    if ans > cost:

        ans = cost

print(ans)
N = int(eval(input()))
S = eval(input())
W_cnt_array = [0] * N
E_cnt_array = [0] * N
W_cnt = 0
E_cnt = 0
for i in range(N):
    if S[i] == "W":
        W_cnt += 1
    elif S[i] == "E":
        E_cnt += 1
    W_cnt_array[i] = W_cnt
    E_cnt_array[i] = E_cnt
prev_dir = S[0]
num = min(max(E_cnt_array), max(W_cnt_array))
for i in range(1, N):
    if prev_dir == "E" and S[i] == "W":
        num = min(num, W_cnt_array[i - 1] + E_cnt_array[-1] - E_cnt_array[i])
    prev_dir = S[i]
print(num)

N = int(eval(input()))
S = eval(input())
cost = S.count("E")
ans = N
for c in S:
    if c == "E":
        cost -= 1
    else:
        if ans > cost:
            ans = cost
        cost += 1
else:
    if ans > cost:
        ans = cost
print(ans)

-W_cnt_array = [0] * N -E_cnt_array = [0] * N -W_cnt = 0 -E_cnt = 0 -for i in range(N): -    if S[i] == "W": -        W_cnt += 1 -    elif S[i] == "E": -        E_cnt += 1 -    W_cnt_array[i] = W_cnt -    E_cnt_array[i] = E_cnt -prev_dir = S[0] -num = min(max(E_cnt_array), max(W_cnt_array)) -for i in range(1, N): -    if prev_dir == "E" and S[i] == "W": -        num = min(num, W_cnt_array[i - 1] + E_cnt_array[-1] - E_cnt_array[i]) -    prev_dir = S[i] -print(num) +cost = S.count("E") +ans = N +for c in S: +    if c == "E": +        cost -= 1 +    else: +        if ans > cost: +            ans = cost +        cost += 1 +else: +    if ans > cost: +        ans = cost +print(ans)