#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

const int MAXN = 1000;
char c[MAXN][MAXN];
int used[MAXN][MAXN] = {};
bool cycle[MAXN][MAXN] = {};
int mas[MAXN][MAXN] = {}, mas1[MAXN][MAXN] = {}, dif[MAXN][MAXN], cur_cycle = 0;
int len_cycle[MAXN * MAXN] = {}, cur_cycle1[MAXN * MAXN] = {};
int cur_used = 1;
int cur2 = 0;

pair<int, int> ss(int i, int j) {
char c1 = c[i][j];
if (c1 == 'E' || c1 == 'e') {
	return make_pair(i, j + 1);
}
if (c1 == 'W' || c1 == 'w') {
	return make_pair(i, j - 1);
}
if (c1 == 'N' || c1 == 'n') {
	return make_pair(i - 1, j);
}
return make_pair(i + 1, j);
}

void dfs_cycle(int i, int j, int cur) {
	pair <int, int> a = ss(i, j);
	int i1 = a.first, j1 = a.second;
	cycle[i][j] = true;
	mas[i][j] = cur;
	dif[i][j] = cur_cycle;
	if (!cycle[i1][j1]) {
		dfs_cycle(i1, j1, cur);
	}
}

void dfs(int i, int j, int cur) {
	pair <int, int> a = ss(i, j);
	int i1 = a.first, j1 = a.second;
	used[i][j] = cur_used;
	mas1[i][j] = cur;
	if (!used[i1][j1]) {
		dfs(i1, j1, cur + 1);
	}
	else {
		if (cur_used == used[i1][j1]) {
			cycle[i1][j1] = true;
			cur_cycle++;
			mas[i1][j1] = cur - mas1[i1][j1] + 1;
			len_cycle[cur_cycle] = mas[i1][j1];
			dfs_cycle(i1, j1, mas[i1][j1]);
		}
	}
}

bool vis[MAXN][MAXN] = {};
int cc = 0;

void dfs1(int i, int j) {
	vis[i][j] = true;
	pair <int, int> a = ss(i, j);
	int i1 = a.first, j1 = a.second;
	if (!cycle[i1][j1]) {
		dfs1(i1, j1);
	}
	else {
		cc = dif[i1][j1];
	}
	dif[i][j] = cc;
}

int main() {
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);

	int n, m;
	bool flag;


	cin >> n >> m;
	cin >> flag;

	int ans1 = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> c[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (!used[i][j]) {
				dfs(i, j, 0);
				cur_used++;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (!vis[i][j] && !cycle[i][j]) {
				dfs1(i, j);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (c[i][j] > 'A' && c[i][j] < 'Z') {
				cur_cycle1[dif[i][j]]++;
			}
		}
	}
	for (int i = 1; i <= cur_cycle; i++) {
		ans += min(cur_cycle1[i], len_cycle[i]);
	}
	cout << ans;
	return 0;
}
/*
3 4 0
SSSS
EESW
ENWW

4 4 0
esSS
nwSS
nNES
NNNW

1 5 0

*/