N = int(eval(input()))

S = eval(input())



cost = list(S).count("E")



ans = 1000000

for si in S:

    if si == "E":

        cost -= 1

    else:

        if cost < ans:

            ans = cost

        cost += 1

else:

    if cost < ans:

        ans = cost

print(ans)
N = int(eval(input()))

S = eval(input())



cost = S.count("E")



ans = 1000000

for si in S:

    if si == "E":

        cost -= 1

    else:

        if cost < ans:

            ans = cost

        cost += 1

else:

    if cost < ans:

        ans = cost

print(ans)
N = int(eval(input()))
S = eval(input())
cost = list(S).count("E")
ans = 1000000
for si in S:
    if si == "E":
        cost -= 1
    else:
        if cost < ans:
            ans = cost
        cost += 1
else:
    if cost < ans:
        ans = cost
print(ans)

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

-cost = list(S).count("E") +cost = S.count("E")