#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7, A = 5e5 + 2;

int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n, x;
    cin >> n >> x;
    ll a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    ll sum = 0;
    for (int i = 0; i <= x; i++) {
        for (int j = 0; i + j <= min(n, x); j++) {
            priority_queue<ll, vector<ll>, greater<ll>> pq;
            for (int k = 0; k < i; k++)
                pq.push(a[k]);
            for (int k = n - 1, c = 0; c < j; c++, k--)
                pq.push(a[k]);
            for (int k = i + j; k < x; k++) {
                if (!pq.empty() && pq.top() < 0) pq.pop();
            }
            ll val = 0;
            while(!pq.empty()) val += pq.top(), pq.pop();
            sum = max(sum, val);
        }
    }
    cout << sum;
    return 0;
}
#include "bits/stdc++.h"
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 100000000;
int dp[300100][2];


int main()
{

	int N; cin >> N;
	string S; cin >> S;
	dp[0][0] = 0;
	dp[0][1] = 0;
	for (int i = 1; i < N; i++) if (S.at(i) == 'E') dp[0][1]++;
	for (int i = 0; i < N-1; i++) {
		if (S.at(i) == 'E') dp[i + 1][0] = dp[i][0];
		else dp[i + 1][0] = dp[i][0] + 1;
		if (S.at(i+1) == 'E') dp[i + 1][1] = dp[i][1] - 1;
		else dp[i + 1][1] = dp[i][1];
	}
	
	int ans = INF;
	for (int i = 0; i < N; i++) chmin(ans, dp[i][0] + dp[i][1]);

	cout << ans << endl;
	return 0;
}
