#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,j,ans;
  string s;
  cin>>n>>s;
  vector<vector<int>> z(2,vector<int>(n+1));
  for(i=1;i<=n;i++){
    for(j=0;j<2;j++) z.at(j).at(i)+=z.at(j).at(i-1);
    if(s.at(i-1)=='E') z.at(0).at(i)++;
    else if(s.at(i-1)=='W') z.at(1).at(i)++;
  }
  ans=n;
  for(i=1;i<=n;i++) ans=min(ans,z.at(1).at(i-1)+z.at(0).at(n)-z.at(0).at(i));
  cout<<ans<<endl;
}
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.00001;

int main() {
    int n;
    cin >> n;
    long long *a = new long long[n];
    multiset<long long> b;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        b.insert(a[i]);
    }
    sort(a,a+n,greater<>());
    int c = 0;
    for(int i = 0;i < n;i++) {
        if(b.find(a[i]) == b.end()) continue;
        b.erase(b.find(a[i]));
        long long t = 1;
        while(t <= a[i]*2) {
            if(b.find(t-a[i]) != b.end()) {
                c++;
                b.erase(b.find(t-a[i]));
                break;
            }
            t = t << 1;
        }
    }
    cout << c << endl;
}
