#include <bits/stdc++.h>
#define INF 1000000009 
using namespace std;

int W[300010],minv=INF,n;

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){
		char c;
		cin>>c;
		W[i]=W[i-1]+(c=='W');
	}
	for(int i=1;i<=n;i++){
		minv=min(minv,n-1-(i-1-W[i-1]+W[n]-W[i]));
	}
	cout<<minv<<endl;
	return 0;
}