#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

const int sz = 1e6;

int res, cycle, r, t;
bool robot[sz], flag[sz];
int type[sz];
int v[sz];
int comp[sz], cyc[sz];

int dfs(int cur, int num) {
	type[cur] = num;
	if (robot[cur]) {
		r++;
	}
	if (type[v[cur]] == 0) {
		int resof = dfs(v[cur], num);
		if (resof == 1) {
			cycle++;
			return !flag[cur];
		}
		else if (resof == -1) {
			type[cur] = t;
			return -1;
		}
	}
	else if (type[v[cur]] == num) {
		flag[v[cur]] = true;
		cycle++;
		return 1;
	}
	else {
		comp[type[v[cur]]] += r;
		t = type[v[cur]];
		type[cur] = t;
		return -1;
	}
	return 0;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	int n, m, g;
	cin >> n >> m >> g;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char cur;
			cin >> cur;
			if (cur == 'N') {
				v[m * i + j]=(m * (i-1) + j);
				robot[m * i + j] = true;
			}
			if (cur == 'S') {
				v[m * i + j]=(m * (i + 1) + j);
				robot[m * i + j] = true;
			}
			if (cur == 'W') {
				v[m * i + j]=(m * i + j - 1);
				robot[m * i + j] = true;
			}
			if (cur == 'E') {
				v[m * i + j]=(m * i + j + 1);
				robot[m * i + j] = true;
			}
			if (cur == 'n') {
				v[m * i + j]=(m * (i - 1) + j);
			}
			if (cur == 's') {
				v[m * i + j]=(m * (i + 1) + j);
			}
			if (cur == 'w') {
				v[m * i + j]=(m * i + j - 1);
			}
			if (cur == 'e') {
				v[m * i + j]=(m * i + j + 1);
			}
		}
	}
	int counter = 1;
	for (int i = 0; i < n * m; i++) {
		if (type[i] == 0) {
			cycle = 0;
			r = 0;
			dfs(i, counter);
			if (cycle > 0) {
				cyc[counter] = cycle;
				comp[counter] = r;
				counter++;
			}
		}
	}
	int res = 0;
	for (int i = 0; i < counter; i++) {
		res += min(cyc[i], comp[i]);
	}
	printf("%d\n", res);
	return 0;
}

