You are given a row of people facing either east or west. You need to appoint a leader and have the rest face the same direction as the leader. Find the minimum number of people who need to change their direction. Constraints: 2 ≤ N ≤ 3 × 10^5, |S| = N, where S_i is either 'E' or 'W'. Input is given as N and the string S. Output the minimum number of people who need to change their direction. Example: For input 5 and "WEEWW", the output is 1.

# Buggy version:
N = int(input())
S = input()
E = S.count("E")
W = 0
ans = N + 1
for s in S:
    if s == "E":
        E -= 1
    ans = min(W + E, ans)
    if s == "W":
        W -= 1
print(ans)

# Fixed version:
N = int(input())
S = input()
E = S.count("E")
W = 0
ans = N + 1
for s in S:
    if s == "E":
        E -= 1
    ans = min(W + E, ans)
    if s == "W":
        W += 1
print(ans)

# Buggy version:
N=int(input())
S=list(input())
nsums=[0]*N

right =0
for s in S:
  if s=='E':right+=1

left =0
min_sum=N
for i in range(N):
  if S[i] == 'E':right-=1
  if S[i]=='W':left+=1
  nsums[i] = right + left
  min_sum = min(min_sum,nsums[i])
print(min_sum)

# Fixed version:
N=int(input())
S=list(input())
nsums=[0]*N

right =0
for s in S:
  if s=='E':right+=1

left =0
min_sum=N
for i in range(N):
  if S[i] == 'E':right-=1
  nsums[i] = right + left
  if S[i]=='W':left+=1

  min_sum = min(min_sum,nsums[i])
print(min_sum)

# Buggy version:
from itertools import*
_, s = open(0)
b, c = [([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]]
print(min(x+y for x, y in zip(b, c)))

# Fixed version:
from itertools import*
input();s = input()
b, c = [([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]]
print(min(x+y for x, y in zip(b, c)))

# Buggy version:
n = int(input())
s = str(input())
E = [0]
W = [0]

for i in range(n):
    if s[i] == "E":
        E.append(E[-1]+1)
        W.append(W[-1])
    else:
        E.append(E[-1])
        W.append(W[-1]+1)

E = E[1:]
W = W[1:]

ans = n*2

for i in range(1,n-1):
    ans = min(ans,W[i-1]+(E[-1] - E[i+1]))

print(ans)

# Fixed version:
n = int(input())
s = str(input())
W = [0]
for i in range(n):
    if s[i] == "W":
        W.append(W[-1]+1)
    else:
        W.append(W[-1])

ans = n

for i in range(n+1):
    ans = min(ans,W[i] + (n-i)-(W[-1] - W[i]))
print(ans)

# Buggy version:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    S = readline().decode('utf-8')
    L = len(S)
    A = [0]*L
    for i in range(L):
        if S[i] == 'E':
            if i == 0:
                A[i] = 1
            else:
                A[i]=A[i-1]+1
        else:
            if i == 0:
                continue
            else:
                A[i]=A[i-1]
    print(A)
    ans = INF
    for i in range(N):
        tmp = 0
        if i>0:
            tmp += i - A[i-1]
        if i<N-1:
            tmp += A[N-1]-A[i]
        ans = min(ans,tmp)
    print(ans)






if __name__ == '__main__':
    main()


# Fixed version:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    S = readline().decode('utf-8')
    L = len(S)
    A = [0]*L
    for i in range(L):
        if S[i] == 'E':
            if i == 0:
                A[i] = 1
            else:
                A[i]=A[i-1]+1
        else:
            if i == 0:
                continue
            else:
                A[i]=A[i-1]
    ans = INF
    for i in range(N):
        tmp = 0
        if i>0:
            tmp += i - A[i-1]
        if i<N-1:
            tmp += A[N-1]-A[i]
        ans = min(ans,tmp)
    print(ans)






if __name__ == '__main__':
    main()

# Buggy version:
N=int(input())
S=input()
DP=[0]*N
l=0
for i,x in enumerate(S):
  DP[i]+=l
  if x=="W":
    l+=1
r=0
for i,y in enumerate(S[::-1]):
  DP[N-1-i]+=r
  if y=="E":
    r+=1
print(N-1-max(DP))
  

# Fixed version:
N = int(input())
S = input()

L = [0]*N

l = 0
for i, x in enumerate(S):
    L[i] += l
    if x == 'E':
        l += 1
r = 0
for i, x in enumerate(S[::-1]):
    L[N-1-i] += r
    if x == 'W':
        r += 1

print(N-1 - max(L))

# Buggy version:
n = int(input())
S = [int(c == 'W') for c in list(input())]
L = [0]
for i in range(n):
    L.append(L[-1]+S[i])
R = [0]
for i in range(n-1, 0, -1):
    R.append(R[-1]+S[i])
R.reverse()
print(min([L[i]+R[i] for i in range(n)]))


# Fixed version:
n = int(input())
S = [int(c == 'W') for c in list(input())]
L = [0]
for i in range(n):
    L.append(L[-1]+S[i])
R = [0]
for i in range(n-1, 0, -1):
    R.append(R[-1]+1-S[i])
R.reverse()
print(min([L[i]+R[i] for i in range(n)]))

# Buggy version:
N=int(input())
S=input()
W=[0]*N
E=[0]*N
for i in range(N):
    if S[i]=='W':
        W[i]=W[i-1]+1
        E[i]=E[i-1]
    else:
        W[i]=W[i-1]
        E[i]=E[i-1]+1
A=[0]*N
A[0]=W[N-1]
if S[0]=='W':
    A[0]=A[0]-1
for i in range(1,N):
    A[i]=W[i-1]+E[N-1]-E[i]
print(min(A))

# Fixed version:
N = int(input())
S = input()

W,E = [0]*N, [0]*N

for i in range(1,N):
    if S[i-1]=='W':
        W[i] = W[i-1]+1
    else:
        W[i] = W[i-1]

S = S[::-1]
for i in range(1,N):
    if S[i-1]=='E':
        E[i] = E[i-1]+1
    else:
        E[i] = E[i-1]
E = E[::-1]

A = [0]*N
for i in range(N):
    A[i] = E[i]+W[i]

ans = min(A)
print(ans)

# Buggy version:
N = int(input())
S = input()

s = S[::-1]
w = [0]*(N+1)
e = [0]*(N+1)
cnt_w = 0
cnt_e = 0

for i in range(N):
    if(S[i] == "W"):
        cnt_w += 1
        w[i+1] = cnt_w
    else:
        w[i+1] = cnt_w

for i in range(N):
    if(s[i] == "E"):
        cnt_e += 1
        e[i+1] = cnt_e
    else:
        e[i+1] = cnt_e

print(w)
print(e)
e = e[::-1]        
ans = 2*N

for i in range(N+1):
    ans = min(ans, e[i]+w[i])
print(ans)

# Fixed version:
N = int(input())
S = input()

s = S[::-1]
w = [0]*(N+1)
e = [0]*(N+1)
cnt_w = 0
cnt_e = 0

for i in range(N):
    if(S[i] == "W"):
        cnt_w += 1
        w[i+1] = cnt_w
    else:
        w[i+1] = cnt_w

for i in range(N):
    if(s[i] == "E"):
        cnt_e += 1
        e[i+1] = cnt_e
    else:
        e[i+1] = cnt_e

e = e[::-1]        
ans = 2*N

for i in range(N+1):
    ans = min(ans, e[i]+w[i])
print(ans)

# Buggy version:
from collections import Counter
n = int(input())
s = input()
c = Counter(s)
tmp = c['E'] - (1 if s[0] == 'E' else 0)
best = tmp
for i in range(1, n):
    if s[i - 1] == 'W'
        tmp += 1
    else:
        tmp -= 1
    if tmp < best:
        best = tmp
print(best)

# Fixed version:
from collections import Counter
n = int(input())
s = input()
c = Counter(s)
tmp = c['E']
best = tmp - (1 if s[0] == 'E' else 0)
for i in range(1, n):
    if s[i - 1] == 'W':
        tmp += 1
    else:
        tmp -= 1
    if tmp - (1 if s[i] == 'E' else 0) < best:
        best = tmp - (1 if s[i] == 'E' else 0)
print(best)

# Buggy version:
n = int(input())
s = input()
lm = [0] *(n+1)
rm = [0] *(n+1)

def check_l(x):
    if x=='W':
        r = 1
    else:
        r = 0
    return r
def check_r(x):
    if x=='E':
        r = 1
    else:
        r = 0
    return r
    
for i in range(1,n):
    lm[i+1] = lm[i] + check_l(s[i-1])
    rm[i] = rm[i+1] + check_r(s[i])
ans = float('inf')
for i in range(1,n+1):
    ans = min(ans,lm[i]+rm[i])
print(ans)

# Fixed version:
n = int(input())
s = input()
lm = [0] *(n+1)
rm = [0] *(n+1)

def check_l(x):
    if x=='W':
        r = 1
    else:
        r = 0
    return r
def check_r(x):
    if x=='E':
        r = 1
    else:
        r = 0
    return r
    
for i in range(1,n):
    lm[i+1] = lm[i] + check_l(s[i-1])
for i in range(n-1,0,-1):
    rm[i] = rm[i+1] + check_r(s[i])
ans = float('inf')
for i in range(1,n+1):
    ans = min(ans,lm[i]+rm[i])
print(ans)

# Buggy version:
N = int(input())
s = input().strip()
d = {"W":0,"E":0}
x=[]
for i, c in enumerate(s):
    x.append(i - d[c])
    d[c]+=1
d = {"W":0,"E":0}
r = N
for i, c in enumerate(s[::-1]):
    r = min(r, x[N-i-1]+d[c])
    d[c]+=1
print(r)


# Fixed version:
N = int(input())
s = input().strip()
d = {"W":0,"E":0}
x=[]
for i, c in enumerate(s):
    x.append(d["W"])
    d[c]+=1
d = {"W":0,"E":0}
r = N
for i, c in enumerate(s[::-1]):
    r = min(r, x[N-i-1]+d["E"])
    d[c]+=1
print(r)

# Buggy version:
from itertools import accumulate
n = int(input())
s = str(input())
tt = [1 if i  == "W" else 0 for i in s]
B = [0] + tt
B = list(accumulate(B))
#print(B)
ans = float('Inf')
for i in range(1,n):
    #w = s[:i].count("W")
    ##W = sum(tt[:i])
    w = B[i]
    #print(W,w)
    #e = s[i:].count("E")
    #E = len(tt[i:]) - sum(tt[i:])
    e = n - i - B[-1] + B[i]
    #print(E,e)
    #ans = min(ans,W+E)
    ans = min(ans,w+e)
print(ans)


# Fixed version:
from itertools import accumulate
n = int(input())
s = str(input())
tt = [1 if i  == "W" else 0 for i in s]
B = [0] + tt
B = list(accumulate(B))
#print(B)
ans = float('Inf')
for i in range(0,n+1):
    #w = s[:i].count("W")
    ##W = sum(tt[:i])
    w = B[i]
    #print(W,w)
    #e = s[i:].count("E")
    #E = len(tt[i:]) - sum(tt[i:])
    e = n - i - B[-1] + B[i]
    #print(E,e)
    #ans = min(ans,W+E)
    ans = min(ans,w+e)
print(ans)

# Buggy version:
N = int(input())
S = list(input())
S = list(map(lambda x: 0 if x == "W" else 1, S))

E = 0
W = sum(S[1:N])

p = W
for i in range(1, N):
  E += 1 - S[i-1]
  W -= S[i]
  ss = E + W
  if ss < p:
    p = ss

    print(p)

# Fixed version:
def main():
    N = int(input())
    S = list(input())
    S = list(map(lambda x: 0 if x == "W" else 1, S))

    E = 0
    W = sum(S[1:N])

    p = W
    for i in range(1, N):
        E += 1 - S[i-1]
        W -= S[i]
        ss = E + W
        if ss < p:
            p = ss

    print(p)


main()

# Buggy version:
from itertools import accumulate

N = int(input())
S = list(input())

A = [0]*(N+1) #N+1まで入れること忘れず

#リーダーの方向を向く，W->1の累積和
for i in range(1, N+1):
    j = 0
    if S[i-1] == "W":
        j = 1
    A[i]=A[i-1] +j
#A =list(accumulate(A))
print(A)

#とするとiより左にいて西を向いている人の最小値
ans=N
for i in range(N):
    val = N-i +A[i] -A[N]
    ans = min(ans, A[i-1] +val)

if ans==0: #剥く人いないとき1
    ans=1

print(ans)

# Fixed version:
from itertools import accumulate

N = int(input())
S = list(input())

A = [0]*(N+1) #N+1まで入れること忘れず

#リーダーの方向を向く，W->1の累積和，[0]start
for i in range(1, N+1):
    j = 0
    if S[i-1] == "W":
        j = 1
    A[i]=A[i-1] +j
#A =list(accumulate(A))
#print(A)

#iより左にいて西を向いている人の最小値
ans=N
for i in range(1, N+1):
    val = N-i +A[i] -A[N]
    ans = min(ans, A[i-1] +val)

print(ans)

# Buggy version:
n = int(input())
s = input()
l = [0]*n
c = 0
for i in range(n-1):
  if s[i+1] == "E":
    c += 1
    if s[i] == "E":
      l[i+1] = l[i] - 1
    else:
      l[i+1] = l[i]
  else:
    if s[i+1] == "W":
      l[i+1] = l[i] + 1
    else:
      l[i+1] = l[i]
ans = min(l) + c
print(ans)

# Fixed version:
n = int(input())
s = input()
l = [0]*n
c = 0
for i in range(n-1):
  if s[i+1] == "E":
    c += 1
    if s[i] == "E":
      l[i+1] = l[i] - 1
    else:
      l[i+1] = l[i]
  else:
    if s[i] == "W":
      l[i+1] = l[i] + 1
    else:
      l[i+1] = l[i]
ans = min(l) + c
print(ans)

# Buggy version:
N = int(input())
S = input()
W = S.count('W')
E = S.count('E')
counter = len(S)
cost = E
for i in range(len(S)):
  if S[i] = 'E':
    cost -= 1
    if cost < counter:
      counter = cost
  else:
    cost +=1
print(counter)

# Fixed version:
N = int(input())
S = input()
W = S.count('W')
E = S.count('E')
counter = len(S)
cost = E
for i in range(len(S)):
  if S[i] == 'E':
    cost -= 1
    if cost < counter:
      counter = cost
  else:
    if cost < counter:
      counter = cost
    cost +=1
print(counter)

# Buggy version:
n = int(input())
s = input()

min_n = s[1:].count('E')
for i in range(1, n):
    tmp_n += s[i-1].count('W') - s[i].count('E')
    min_n = min(tmp_n, min_n)

print(min_n)

# Fixed version:
n = int(input())
s = input()

min_n = s[1:].count('E')
tmp_n = min_n
for i in range(1, n):
    tmp_n += s[i-1].count('W') - s[i].count('E')
    min_n = min(tmp_n, min_n)

print(min_n)

# Buggy version:
n=int(input())
s=str(input())

l=[]
c=s.count('E',1)
for i in range(1,n):
    if s[i-1]=='W':
        c+=1
    if s[i]=='E':
        c-=1
    l.append(c)
print(min(l))


# Fixed version:
n=int(input())
s=str(input())

l=[]
c=s.count('E',1)
for i in range(1,n):
    if s[i-1]=='W':
        c+=1
    if s[i]=='E':
        c-=1
    l.append(c)
print(min(min(l),s.count('E')))

# Buggy version:
N=int(input())
S=input()
l=0
r=S[1:].count("E")
print(r)
answer=N

for i in range(N-1):
    if l+r<answer:
        answer=l+r
    if S[i]=="W":
        l+=1
    if S[i+1]=="E":
        r-=1
if l+r<answer:
    answer=l+r
print(answer)


# Fixed version:
N = int(input())
S = input()

lW = 0
rE = S[1:N].count("E")
mi = lW + rE
for i in range(1, N):
    if S[i - 1] == "W":
        lW += 1
    if S[i] == "E":
        rE -= 1
    if lW + rE < mi:
        mi = lW + rE

print(mi)

# Buggy version:
N = int(input())
S = input()
ans = [S[1:].count("E")]
for i in range(1, N):
	tmp = ans[i - 1]
	if S[i - 1] == "W":
		tmp += 1
	if S[i] == "E":
		tmp -= 1
	ans.append(tmp)
print(ans)


# Fixed version:
N = int(input())
S = input()
ans = [S[1:].count("E")]
for i in range(1, N):
	tmp = ans[i - 1]
	if S[i - 1] == "W":
		tmp += 1
	if S[i] == "E":
		tmp -= 1
	ans.append(tmp)
print(min(ans))

# Buggy version:
N = int(input())
S = input()

rcost = 0
lcost = S.count('E')
ans = lcost

for i in range(N-1):
        if S[i] == 'W':
            rcost += 1
        if S[i+1] == 'E':
            lcost -= 1
        print(rcost,lcost)
        ans = min(ans, rcost+lcost)
    
print(ans)

# Fixed version:
N = int(input())
S = input()

rcost = 0
lcost = S.count('E')
if S[0] == 'E':
    lcost -= 1
ans = lcost

for i in range(N-1):
        if S[i] == 'W':
            rcost += 1
        if S[i+1] == 'E':
            lcost -= 1
        ans = min(ans, rcost+lcost)
    
print(ans)

# Buggy version:
n=int(input())
w=input()
ans=[0 for i in range(n)]
for i in range(1,n):
  if w[i]=="E":
    ans[0]+=1
for i in range(1,n):
  if w[i]=="E":
    ans[i]=ans[i-1]-1
  if w[i-1]=="W":
    ans[i]=ans[i-1]+1
print(min(ans))
    

# Fixed version:
n=int(input())
w=input()
ans=[0 for i in range(n)]
for i in range(1,n):
  if w[i]=="E":
    ans[0]+=1
for i in range(1,n):
  ans[i]=ans[i-1]
  if w[i]=="E":
    ans[i]-=1
  if w[i-1]=="W":
    ans[i]+=1
print(min(ans))

# Buggy version:
n=int(input())
s=input()
e,w=s.count('E'),s.count('W')
le,lw=0,0
ans=10**6
for c in s:
	if c=='E':
		e-=1
		ans=min(ans,e+lw)		
	else:
		lw+=1
print(ans)

# Fixed version:
n=int(input())
s=input()
e,w=s.count('E'),s.count('W')
le,lw=0,0
ans=e
for c in s:
	if c=='E':
		e-=1
		ans=min(ans,e+lw)		
	else:
		lw+=1
print(ans)

# Buggy version:
N = int(input())
S = input()

East = [0] * N
West = [0] * N

for i,s in enumerate(list(S)):
    if s == 'W' : 
        if i==0:
            East[i] = 1
        else:
            East[i] = East[i-1] + 1
    else:
        East[i] = East[i-1]
i = N-1
for s in reversed((list(S))):
    if s == 'E' : 
        if i==N-1:
            West[i] = 1
        else:
            West[i] = West[i+1] + 1
    else:
        West[i] = West[i+1]
    i -= 1
            
ans = 2**31-1

for i in range(N):
    if i == 1:
        ans2 = West[1]
    elif i == N-1:
        ans2 = East[N-2]
    else:
        ans2 = East[i-1]+West[i+1]
    ans = min(ans,ans2)
    
print(ans)
    

# Fixed version:
N = int(input())
S = input()

East = [0] * N
West = [0] * N

for i,s in enumerate(list(S)):
    if s == 'W' : 
        if i==0:
            East[i] = 1
        else:
            East[i] = East[i-1] + 1
    else:
        if i == 0:
            East[i] = 0
        else:
            East[i] = East[i-1]
i = N-1
for s in reversed((list(S))):
    if s == 'E' : 
        if i==N-1:
            West[i] = 1
        else:
            West[i] = West[i+1] + 1
    else:
        if i == N-1:
            West[i] = 0
        else:
            West[i] = West[i+1]
    i -= 1
            
ans = 2**31-1

for i in range(N):
    if i == 1:
        ans2 = West[1]
    elif i == N-1:
        ans2 = East[N-2]
    else:
        ans2 = East[i-1]+West[i+1]
    ans = min(ans,ans2)
    
print(ans)

# Buggy version:
N = int(input())
S = input()
MIN = float('inf')
left = 0
right = S.count('E')
for i in range(N):
  if S[i] == 'W':
    left += 1
  else:
    right -= 1
  MIN = min(left+right,MIN)
print(MIN)
  

# Fixed version:
N = int(input())
S = input()
left = 1 if S[0] == 'W' else 0
right = S[1:].count('E')
MIN =  right 
for i in range(1,N):
  if S[i] == 'W':
    MIN = min(MIN,left+right)
    left += 1
  else:
    MIN = min(MIN,left+right)
    right -= 1
  
  if i==N-1:
    MIN = min(MIN,S[:i].count('W'))

print(MIN)

# Buggy version:
n=int(input())
s=list(input())
p=[0,0]
l=[s.count("E"),s.count("W")]
t=[]
for i in range(n):
    if s[i]=="E":
        t.append(l[0]+p[1]-1)
        l[0]-=1
        p[0]+=1
    else:
        t.append(l[1]+p[0])
        l[1]-=1
        p[1]+=1
print(min(t))

# Fixed version:
n=int(input())
s=list(input())
p=[0,0]
l=[s.count("E"),s.count("W")]
t=[]
for i in range(n):
    if s[i]=="E":
        t.append(l[0]+p[1]-1)
        l[0]-=1
        p[0]+=1
    else:
        t.append(l[0]+p[1])
        l[1]-=1
        p[1]+=1
print(min(t))

# Buggy version:
n = input()
s = input()

ans = 0
count = 0

for i in s:
    if i == 'w':
        count += 1
    elif count:
        count -= 1
        ans += 1
    else:
        pass


print(ans)


# Fixed version:
n = input()
s = input()

ans = 0
count = 0

for i in s:
    if i == 'W':
        count += 1
    elif count:
        count -= 1
        ans += 1
    else:
        pass


print(ans)

# Buggy version:
N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
count = count_E + count_W
ans = count
for i in range(N):
    if i == 0 and S[i] == "E":
        count_E -= 1
    else:
        if S[i-1] == "E" and i != 1:
            count_E -= 1
        elif S[i-1] == "W":
            count_W += 1
    if count < ans :
        ans = count
print(ans)

# Fixed version:
N = int(input())
S = list(input())
count_E = S.count("E")
count_W = 0
ans = count_E
for i in range(N):
    if S[i] == "E":
        count_E -= 1
    if S[i-1] == "W" and i != 0:
        count_W += 1
    if count_E + count_W < ans :
        ans = count_E + count_W
print(ans)

# Buggy version:
def main():
	N = int(input())
	a = input()
    
	W = [0]
	E = [0]
	for i in range(N):
		if a[i] == 'W':
			W[i+1] = W[i] + 1
			E[i+1] = E[i]
		else:
			W[i+1] = W[i]
			E[i+1] = E[i] + 1
	E_max = E[-1]
	n_min = N
	for i in range(N):
		t = W[i] + E_max - E[i+1]
		if t < n_min:
			n_min = t
	print (n_min)
main()

# Fixed version:
def main():
	N = int(input())
	a = input()
    
	W = [0]*(N+1)
	E = [0]*(N+1)
	for i in range(N):
		if a[i] == 'W':
			W[i+1] = W[i] + 1
			E[i+1] = E[i]
		else:
			W[i+1] = W[i]
			E[i+1] = E[i] + 1
	E_max = E[-1]
	n_min = N
	for i in range(N):
		t = W[i] + E_max - E[i+1]
		if t < n_min:
			n_min = t
	print (n_min)
main()

# Buggy version:
N = int(input())
line = input()

ans = line[1:N].count('E')
tmp = ans
for i in range(1,N):
 if line[i] == 'E':
  tmp -= 1
 if line[i-1] == 'W':
  tmp += 1
 if ans>tmp:
  ans = tmp
 print(i)


print(ans)

# Fixed version:
N = int(input())
line = input()

ans = line[1:N].count('E')
tmp = ans
for i in range(1,N):
 if line[i] == 'E':
  tmp -= 1
 if line[i-1] == 'W':
  tmp += 1
 if ans>tmp:
  ans = tmp

print(ans)

# Buggy version:
N=int(input())
S=input()
DP=[0]**N
DP[0]=S[1:].count("E")
for i in range(1,N):
  if S[i]=="E":
    DP[i]=DP[i-1]-1+S[:i].count("W")
  else:
    DP[i]=DP[i-1]+S[:i].count("W")
print(min(DP))


# Fixed version:
N = int(input())
S = input()
E = S.count('E')
W = 0
result = E
for i in range(N):
    if S[i] == 'E':
        E -= 1
    else:
        W += 1
    result = min(result,E+W)
print(result)

# Buggy version:
input()
ss = input()
loss = ss[1:].count("E")
min_loss = loss
ss_before = ss[:-1]
ss_after = ss[1:]
for b, a in zip(ss_before, ss_after):
    if b == "E":
        loss -=1
    else:
        loss +=1
    if a == "W":
        loss -=1
    else:
        loss +=1
    if loss < min_loss:
        min_loss = loss
print("{}".format(min_loss))
    

# Fixed version:
input()
ss = input()
loss = ss[1:].count("E")
min_loss = loss
ss_before = ss[:-1]
ss_after = ss[1:]
for b, a in zip(ss_before, ss_after):
    loss += b == "W"
    loss -= a == "E"
    if loss < min_loss:
        min_loss = loss
print("{}".format(min_loss))

# Buggy version:
N = int(input())
S = input()
 
ans = len(S) - 1
left = 0
right = S[0:].count("E")

for i in range(1, N):
    if S[i - 1] == "W":
        left += 1
    if S[i] == "E":
        right -= 1 
    ans = min(ans, left + right)
print(ans)

# Fixed version:
N = int(input())
S = input()

left = 0
right = S[1:].count('E')
result = left + right

for i in range(1, N):
	if S[i - 1] == "W":
		left += 1
	if S[i] == "E":
		right -= 1
	result = min(result, left + right)
print(result)

# Buggy version:
N = input()
S = list(input())

min_num = 300000
left = 0

for i in range(len(S)):

  if i > 0:
    left += int(S[i] == "W")
    
  right = S[i+1: ].count("E")

  if left + right < min_num:
    min_num = left + right

print(min_num)


# Fixed version:
N = input()
S = list(input())

length = len(S)
min_num = 300000
left = 0
right = S.count("E")

for i in range(length):

  if i > 0:
    left += int(S[i - 1] == "W")

  if i < length:
    right -= int(S[i] == "E")

  if left + right < min_num:
    min_num = left + right

print(min_num)

# Buggy version:
def foo (s):
    ans = 0
    count = 0
    for i in s:
        if i == 'W':
        count += 1
    elif count :
        count -= 1
        ans += 1
    else:
        pass
    return ans

n = input()
s = input()
 
print(foo(s))

# Fixed version:
def foo (s):
    ans = 0
    count = 0
    for i in s:
        if i == 'W':
            count += 1
        elif count :
            count -= 1
            ans += 1
        else:
            pass
    return ans

n = input()
s = input()
 
print(foo(s))

# Buggy version:
def foo (s):
	ans = 0
	count = 0
	for i in s:
		if   (not count) and (i == 'E'):pass
		elif not count: count += 1
		elif i == 'E': count -= 1; ans += 1
		else: count += 1
	return ans
  
  n = int(input())
  s = input()
  print(foo(s))

# Fixed version:
def foo (s):
	ans = 0
	count = 0
	for i in s:
		if   (not count) and (i == 'E'):pass
		elif not count: count += 1
		elif i == 'E': count -= 1; ans += 1
		else: count += 1
	return ans

n = input()
s = input()

print(foo(s))

# Buggy version:
n = int(input())
a = list(input())
for i in range(n):
    if a[i] == 'E':
        a[i] = 1
    else:
        a[i] = 0

ans = 99999999999999999999
# print(a)
l = 0
r = sum(a)
for i in range(n):

    if i == 0:
        if a[i] == 1:
            r -= a[i]
            a[i] = 0
        else:
            a[i] = 1
        l = 0
    else:
        if a[i] == 1:
            a[i] = 0
            r -= 1
        else:
            a[i] = 1
        l += a[i-1]

    ans = min(l+r,ans)
    print(i,l,r,ans)
print(ans)



# Fixed version:
n = int(input())
a = list(input())
for i in range(n):
    if a[i] == 'E':
        a[i] = 1
    else:
        a[i] = 0

ans = 99999999999999999999
# print(a)
l = 0
r = sum(a)
for i in range(n):

    if i == 0:
        if a[i] == 1:
            r -= a[i]
            a[i] = 0
        else:
            a[i] = 1
        l = 0
    else:
        if a[i] == 1:
            a[i] = 0
            r -= 1
        else:
            a[i] = 1
        l += a[i-1]

    ans = min(l+r,ans)
    # print(i,l,r,ans)
print(ans)

# Buggy version:
def solve():
    N = int(input())
    S = input()

    AW = [0]*(N+1)
    AE = [0]*(N)

    wcount = 0
    ecount = 0
    for i in range(N):
        if S[i] == "W":
            wcount += 1
        else:
            ecount += 1
        AW[i] = wcount
        AE[i] = ecount

    MIN = 1000000

    for i in range(N):
        tmp = 0
        tmp += AW[i-1]
        tmp += AE[-1] - AE[i]
        MIN = min(MIN, tmp)
    print(MIN)

if __name__ == "__main__":
    local_test()
    solve()

# Fixed version:
def solve():
    N = int(input())
    S = input()

    AW = [0]*(N+1)
    AE = [0]*(N)

    wcount = 0
    ecount = 0
    for i in range(N):
        if S[i] == "W":
            wcount += 1
        else:
            ecount += 1
        AW[i] = wcount
        AE[i] = ecount

    MIN = 1000000

    for i in range(N):
        tmp = 0
        tmp += AW[i-1]
        tmp += AE[-1] - AE[i]
        MIN = min(MIN, tmp)
    print(MIN)

if __name__ == "__main__":
    solve()