#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <cassert>
#include <iomanip>
/*#include <ext/pb_ds/assoc_container.hpp>	// Common file
#include <ext/pb_ds/tree_policy.hpp> 		// Including */
using namespace std;
//using namespace __gnu_pbds;
/*
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename F, typename S>
using ordered_map = tree<F, S, less<F>, rb_tree_tag, tree_order_statistics_node_update>;
*/
 
typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <vi> vvi;
typedef vector <vl> vvl;
typedef pair <int,int> pii;
typedef pair <double, double> pdd;
typedef pair <ll, ll> pll;
typedef vector <pii> vii;
typedef vector <pll> vll;
typedef vector<int>:: iterator vit;
typedef set<int>:: iterator sit;
 
 
const double PI  =      acos(-1.0);
const double eps =      1e-8;
const long inf   =      0x3f3f3f3f;
const ll infLL   =      (1ll << 62);
const double oo  =      1e15;
 
 
#define FOR(i,a,b)      for(i = a; i <= b; ++i)
#define REP(i,a,b)      for(i = a; i >= b; --i)
#define pb              push_back
#define eb              emplace_back
#define F               first
#define S               second
#define all(a)          a.begin(),a.end()
#define mp              make_pair
#define pf              printf
#define sf              scanf
//#define left            __left
//#define right           __right
//#define tree            __tree
#define inp(f)         freopen(f,"r",stdin)
#define out(f)         freopen (f,"w",stdout)
#define CHAR            getchar()
#define mxe(a,n)        (*max_element(a,a+n))
#define mne(a,n)        (*min_element(a,a+n))
#define SUM(a,n)        (accumulate(a,a+n,0)) // returns sum of all the values in the array //
#define countbit(x)     __builtin_popcountll(x) // counts number of 1's in binary representation //
#define trail_zero(x)   __builtin_ctz(x) 
//#define MOD             1000000007
#define RESET(a,b)      memset(a,b,sizeof(a))
#define CLR(a)          memset(a,0,sizeof(a))
#define SET(a)          memset(a,-1,sizeof(a))
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a * (b / gcd(a,b)))
#define sqr(a)          ((a) * (a))
//#define harmonic(n)     0.57721566490153286l+log(n)
#define optimize()      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction()      cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define what_is(x)      cerr << #x << " is " << x << endl;
 
/*----------------------Graph Moves----------------*/
//const int fx[] = {+1, -1, +0, +0};
//const int fy[] = {+0, +0, +1, -1};
//const int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};   	// Kings Move
//const int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};  	// Kings Move
//const int fx[] = {-2, -2, -1, -1,  1,  1,  2,  2};	// Knights Move
//const int fy[] = {-1,  1, -2,  2, -2,  2, -1,  1};	// Knights Move
/*------------------------------------------------*/
 
inline bool     checkBit (ll n, int i) { return n&(1LL<<i); }
inline ll       setBit (ll n, int i) { return n|(1LL<<i);; }
inline ll       resetBit (ll n, int i) { return n&(~(1LL<<i)); }
inline bool     EQ (double a, double b) { return fabs(a-b) < 1e-9; }
inline bool     isLeapYear (ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline bool     isInside (pii p,ll n,ll m) { return (p.first>=0&&p.first<n&&p.second>=0&&p.second<m); }
inline bool     isInside (pii p,ll n) { return (p.first>=0&&p.first<n&&p.second>=0&&p.second<n); }
inline bool     isSquare (ll x) { ll s = sqrt(x);	return (s*s==x); }
inline bool     isFib (ll x) { return isSquare(5*x*x+4)|| isSquare(5*x*x-4); }
inline bool     isPowerOfTwo (ll x) { return (x && !(x & (x - 1))); }
inline void     normal (ll &a, ll MOD) { a %= MOD; (a < 0) && (a += MOD); }
inline ll       modMul (ll a, ll b, ll MOD) { a %= MOD, b %= MOD; normal(a, MOD), normal(b, MOD); return (a*b)%MOD; }
inline ll       modAdd (ll a, ll b, ll MOD) { a %= MOD, b %= MOD; normal(a, MOD), normal(b, MOD); return (a+b)%MOD; }
inline ll       modSub (ll a, ll b, ll MOD) { a %= MOD, b %= MOD; normal(a, MOD), normal(b, MOD); a -= b; normal(a, MOD); return a; }
inline ll       modPow (ll b, ll p, ll MOD) { ll r = 1; while(p) { if(p&1) r = modMul(r, b, MOD); b = modMul(b, b, MOD); p >>= 1; } return r; }
inline ll       modInverse (ll a, ll MOD)   { return modPow(a, MOD-2, MOD); }
inline ll       modDiv (ll a, ll b, ll MOD) { return modMul(a, modInverse(b, MOD), MOD); }


using namespace std;
int main()
{
	int n;
	string s;
	cin>>n>>s;
	int w[300001],e[300001];
	if(s[0]=='W')
		w[0]=1;
	else
		e[0]=1;
	for(int i=1;i<n;i++)
	{
		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;
		}
	}
	int min=e[n-1];
	for(int i=1;i<n;i++)
	{
		int left=w[i-1];
		int right=e[n-1]-e[i];
		if(left+right<min)
			min=left+right;	
	}
	cout<<min<<endl;	
	return 0;
}

Measured memory_bytes: 3076