from sys import stdin





def main():

    N = int(stdin.readline().rstrip())

    S = stdin.readline()

    count = 0

    s1 = []

    for i, x in enumerate(S):

        if x == 'W':

            count += 1

        s1.append(count)

    count = 0

    s2 = []

    for i, x in enumerate(S[::-1]):

        if x == 'E':

            count += 1

        s2.append(count)

    s2.reverse()



    result = N

    for i in range(N):

        count = 0

        idx = i - 1

        if idx >= 0:

            count += s1[idx]

        idx = i + 1

        if idx < N:

            count += s2[idx]

        result = min(result, count)



    print(result)





if __name__ == '__main__':

    main()

from sys import stdin





def main():

    N = int(stdin.readline().rstrip())

    S = stdin.readline().rstrip()

    spam1 = [0]

    for x in S[:-1]:

        spam1 += [spam1[-1] + 1 if x == 'W' else spam1[-1]]

    spam2 = [0]

    for x in S[::-1][:-1]:

        spam2 += [spam2[-1] + 1 if x == 'E' else spam2[-1]]

    spam2 = spam2[::-1]

    print((min([spam1[i] + spam2[i] for i in range(N)])))





if __name__ == '__main__':

    main()

from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline()
    count = 0
    s1 = []
    for i, x in enumerate(S):
        if x == "W":
            count += 1
        s1.append(count)
    count = 0
    s2 = []
    for i, x in enumerate(S[::-1]):
        if x == "E":
            count += 1
        s2.append(count)
    s2.reverse()
    result = N
    for i in range(N):
        count = 0
        idx = i - 1
        if idx >= 0:
            count += s1[idx]
        idx = i + 1
        if idx < N:
            count += s2[idx]
        result = min(result, count)
    print(result)


if __name__ == "__main__":
    main()

from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline().rstrip()
    spam1 = [0]
    for x in S[:-1]:
        spam1 += [spam1[-1] + 1 if x == "W" else spam1[-1]]
    spam2 = [0]
    for x in S[::-1][:-1]:
        spam2 += [spam2[-1] + 1 if x == "E" else spam2[-1]]
    spam2 = spam2[::-1]
    print((min([spam1[i] + spam2[i] for i in range(N)])))


if __name__ == "__main__":
    main()

-    S = stdin.readline() -    count = 0 -    s1 = [] -    for i, x in enumerate(S): -        if x == "W": -            count += 1 -        s1.append(count) -    count = 0 -    s2 = [] -    for i, x in enumerate(S[::-1]): -        if x == "E": -            count += 1 -        s2.append(count) -    s2.reverse() -    result = N -    for i in range(N): -        count = 0 -        idx = i - 1 -        if idx >= 0: -            count += s1[idx] -        idx = i + 1 -        if idx < N: -            count += s2[idx] -        result = min(result, count) -    print(result) +    S = stdin.readline().rstrip() +    spam1 = [0] +    for x in S[:-1]: +        spam1 += [spam1[-1] + 1 if x == "W" else spam1[-1]] +    spam2 = [0] +    for x in S[::-1][:-1]: +        spam2 += [spam2[-1] + 1 if x == "E" else spam2[-1]] +    spam2 = spam2[::-1] +    print((min([spam1[i] + spam2[i] for i in range(N)])))