N = int(eval(input()))

S = eval(input())

x = S.count('E')

ans = x

for s in S:

    if s == 'E':

        x -= 1

        if ans > x:

            ans = x

    else:

        x += 1

    if ans > x:

        ans = x

print(ans)

N = int(eval(input()))

S = eval(input())

x = S.count('E')

ans = x

for s in S:

    if s == 'E':

        x -= 1

        if ans > x:

            ans = x

    else:

        x += 1

print(ans)

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

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

-    if ans > x: -        ans = x