#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(s...)  fprintf(stderr, s)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }


int H, W;
char F[111][111];

int A[101][101];
short dp[101][101][101][101];
short box(int l, int u, int r, int d) {
    return A[d][r] - A[d][l] - A[u][r] + A[u][l];
}

int main() {
    scanf("%d%d", &H, &W);
    REP (i, H) scanf("%s", F[i]);

    int si, sj;

    REP (i, H) REP (j, W) {
	if (F[i][j] == 'E') {
	    si = i;
	    sj = j;
	}
	A[i+1][j+1] = A[i][j+1] + A[i+1][j] - A[i][j];
	if (F[i][j] == 'o') A[i+1][j+1] ++;
    }


    int ans = 0;
    REP (l, sj+1) REP (r, W-sj) REP (u, si+1) REP (d, H-si) {
	short cur = dp[l][r][u][d];
	amax(ans, (int)cur);

	int R, L, D, U;

	U = max(si-u, d); D = min(si+d+1, H-u);
	if (sj-1-l >= r && U < D) amax<short>(dp[l+1][r][u][d], cur + box(sj-1-l, U, sj-l, D));
	if (sj+1+r < W-l && U < D) amax<short>(dp[l][r+1][u][d], cur + box(sj+1+r, U, sj+2+r, D));

	L = max(sj-l, r); R = min(sj+r+1, W-l);
	if (si-1-u >= d && L < R) amax<short>(dp[l][r][u+1][d], cur + box(L, si-1-u, R, si-u));
	if (si+1+d < H-u && L < R) amax<short>(dp[l][r][u][d+1], cur + box(L, si+1+d, R, si+2+d));
    }

    printf("%d\n", ans);



    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, K;
    cin >> N >> K;
    vec X(N);
    REP(i,0,N) cin >> X[i];

    ll p = N;
    REP(i,0,N) {
        if(X[i] >= 0) {
            if(X[i] == 0) {
                X.erase(X.begin() + i);
                --K;
            }
            p = i;
            break;
        }
    }

    ll left, right; 
    if(p < K) {
        left = 0;
        right = K - 1;
    }
    else {
        left = p - K;
        right = p - 1;
    }

    ll m = INF;
    if(K == 0) m = 0;
    else {
        while(left <= p && right < N) {
            ll t;
            if(X[left] < 0 && X[right] < 0) t = -X[left];
            else if(X[left] < 0) t = MIN(X[right]-2*X[left],X[right]*2-X[left]);
            else t = X[right];
            m = MIN(m,t);
            ++left;
            ++right;
        }
    }
    PR(m);

    return 0;
}

/*



*/