#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2000+5,base=2001*3;
int f[N*3][N*6],mod;
void add(int &x,int y){
	x=(x+y)%mod;
}
signed main(){
	int n;
	cin>>n>>mod;
	n*=3;
	f[0][base]=1;
	for(int i=0;i<n;++i)
		for(int j=-i;j<=i;++j)
			if(f[i][j+base]){
				add(f[i+1][j+1+base],f[i][j+base]);
				add(f[i+2][j-1+base],1ll*f[i][j+base]*(i+1)%mod);
				add(f[i+3][j+base],1ll*f[i][j+base]*(i+1)%mod*(i+2)%mod);
			}
	int ans=0;
	for(int j=0;j<=n;++j)
		add(ans,f[n][j+base]);
	cout<<ans;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;

    string s;
    cin >> s;

    vector<int> pref(n, 0), suff(n, 0);

    for (int i = 1; i < n; i++) {
        pref[i] = pref[i-1] + (s[i-1] == 'W');
    }
    for (int i = n-2; i >= 0; i--) {
        suff[i] = suff[i+1] + (s[i+1] == 'E');
    }

    int ans = 1e8;
    for (int i = 0; i < n; i++) {
        ans = min(ans, pref[i] + suff[i]);
    }

    cout << ans << endl;
}