n=int(eval(input()))

S=eval(input())

w,e='W','E'

if e not in S or w not in S:print((0));exit()

ecnt=len([1 for i in list(S) if i==e])

p0,p1=0,ecnt-int(S[0]==e)

ans=p0+p1

for i in range(1,n):

  p0,p1=(p0+int(S[i-1]==w),p1-int(S[i]==e))

  #(l and gyaku,r and gyaku)

  ans=min(ans,p0+p1)

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

S=eval(input())

w,e='W','E'

if e not in S or w not in S:print((0));exit()

ecnt=len([1 for i in list(S) if i==e])

p0,p1=0,ecnt-int(S[0]==e)

ans=p0+p1

p=S[0]

for i in S[1:]:

  p0,p1=(p0+int(p==w),p1-int(i==e))

  #(l and gyaku,r and gyaku)

  ans=min(ans,p0+p1)

  p=i

print(ans)
n = int(eval(input()))
S = eval(input())
w, e = "W", "E"
if e not in S or w not in S:
    print((0))
    exit()
ecnt = len([1 for i in list(S) if i == e])
p0, p1 = 0, ecnt - int(S[0] == e)
ans = p0 + p1
for i in range(1, n):
    p0, p1 = (p0 + int(S[i - 1] == w), p1 - int(S[i] == e))
    # (l and gyaku,r and gyaku)
    ans = min(ans, p0 + p1)
print(ans)

n = int(eval(input()))
S = eval(input())
w, e = "W", "E"
if e not in S or w not in S:
    print((0))
    exit()
ecnt = len([1 for i in list(S) if i == e])
p0, p1 = 0, ecnt - int(S[0] == e)
ans = p0 + p1
p = S[0]
for i in S[1:]:
    p0, p1 = (p0 + int(p == w), p1 - int(i == e))
    # (l and gyaku,r and gyaku)
    ans = min(ans, p0 + p1)
    p = i
print(ans)

-for i in range(1, n): -    p0, p1 = (p0 + int(S[i - 1] == w), p1 - int(S[i] == e)) +p = S[0] +for i in S[1:]: +    p0, p1 = (p0 + int(p == w), p1 - int(i == e)) +    p = i