#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector< vector<char> > arr;
vector< vector<char> > is;
vector< vector<char> > used;
vector< vector<int> > cycle;
vector< vector < pair<int, int> > > cycleis;
vector< vector<char> > use;
int ans = 0;

void dfs(int a, int b, int k) {
	used[a][b] = 1;
	if (is[a][b]) { k++; }
	int x = a, y = b;
	if (arr[a][b] == 'E') { y++; }
	else {
		if (arr[a][b] == 'W') { y--; }
		else {
			if (arr[a][b] == 'N') { x--; }
			else { x++; }
		}
	}
	if (used[x][y]) {
		if (cycleis[x][y].first == -1) { cycleis[x][y] = { x, y }; }
		cycle[cycleis[x][y].first][cycleis[x][y].second] += k;
	}
	else { dfs(x, y, k); }
	cycleis[a][b] = cycleis[x][y];
	return;
}

void likedfs(int a, int b, int len, int k) {
	bool it = 1;
	while (it) {
		use[a][b] = 1;
		k += cycle[a][b];
		len++;
		int x = a, y = b;
		if (arr[a][b] == 'E') { y++; }
		else {
			if (arr[a][b] == 'W') { y--; }
			else {
				if (arr[a][b] == 'N') { x--; }
				else { x++; }
			}
		}
		if (use[x][y]) { ans += min(len, k); it = 0; }
		else { a = x; b = y; }
	}
	return;
}

int main() {
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	int n, m, g;
	cin >> n >> m >> g;
	arr.resize(n);
	is.resize(n);
	for (int i = 0; i < n; i++) {
		arr[i].resize(m);
		is[i].resize(m);
	}
	char c;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> c;
			if (int(c) < 97) { is[i][j] = 1; }
			else { c = char(int(c) - 32); }
			arr[i][j] = c;
		}
	}
	used.resize(n);
	cycle.resize(n);
	cycleis.resize(n);
	for (int i = 0; i < n; i++) {
		used[i].resize(m);
		cycle[i].resize(m);
		cycleis[i].resize(m, { -1, -1 });
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (is[i][j] && !used[i][j]) { dfs(i, j, 0); }
		}
	}
	use.resize(n);
	for (int i = 0; i < n; i++) {
		use[i].resize(m);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (!use[i][j] && cycle[i][j] != 0) { likedfs(i, j, 0, 0); }
		}
	}
	cout << ans;


	return 0;
}