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

#pragma comment(linker, "/stack:268435456")

#define ll long long
#define ld long double
#define sz(x) (int) x.size()
#define mp make_pair

#define TASKNAME "robots"

using namespace std;

const int N = 1005;

int n, m, full;

vector<int> g[N * N];
vector<int> h[N * N];
bool a[N * N];
int sorted[N * N];
bool visited[N * N];
int comp[N * N];
int color;
vector<int> adj[N * N];
int cnt[N * N];
int dp[N * N];
int comp_size[N * N];

int get(int i, int j) {
	return i * m + j;
}

int tmr;

void dfs1(int v) {
	visited[v] = 1;
	for (int u : g[v]) {
		if (!visited[u]) {
			dfs1(u);
		}
	}

	sorted[tmr++] = v;
}

void dfs2(int v) {
	visited[v] = 1;
	comp[v] = color;
	comp_size[color]++;
	for (int u : h[v]) {
		if (!visited[u]) {
			dfs2(u);
		}
	}
}

void calc(int v) {
	dp[v] = cnt[v];
	visited[v] = 1;
	for (int u : adj[v]) {
		if (!visited[u]) {
			calc(u);
			dp[v] += dp[u];
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#else
	freopen(TASKNAME ".in", "r", stdin);
	freopen(TASKNAME ".out", "w", stdout);
#endif

	cin >> n >> m >> full;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			int id = get(i, j);
			if (c == 'N') {
				a[id] = 1;
				g[id].push_back(get(i - 1, j));
			}
			else if (c == 'n') {
				g[id].push_back(get(i - 1, j));
			}
			else if (c == 'S') {
				a[id] = 1;
				g[id].push_back(get(i + 1, j));
			}
			else if (c == 's') {
				g[id].push_back(get(i + 1, j));
			}
			else if (c == 'E') {
				a[id] = 1;
				g[id].push_back(get(i, j + 1));
			}
			else if (c == 'e') {
				g[id].push_back(get(i, j + 1));
			}
			else if (c == 'W') {
				a[id] = 1;
				g[id].push_back(get(i, j - 1));

			}
			else if (c == 'w') {
				g[id].push_back(get(i, j - 1));
			}
		}
	}

	const int K = (n - 1) * m + (m - 1) + 1;

	for (int i = 0; i < K; i++) {
		for (int j : g[i]) {
			h[j].push_back(i);
		}
	}

	for (int i = 0; i < K; i++) {
		if (!visited[i]) {
			dfs1(i);
		}
	}
	
	fill(visited, visited + K, 0);

	for (int i = K - 1; i >= 0; i--) {
		if (!visited[sorted[i]]) {
			dfs2(sorted[i]);
			color++;
		}
	}

	for (int i = 0; i < K; i++) {
		int c = comp[i];
		cnt[c] += a[i];
		for (int j : g[i]) {
			adj[c].push_back(comp[j]);
		}
	}

	fill(visited, visited + K, 0);
	
	int ans = 0;

	for (int i = 0; i < color; i++) {
		if (comp_size[i] > 1) {
			calc(i);
			ans += min(dp[i], comp_size[i]);
		}
	}

	cout << ans << endl;

#ifdef _DEBUG
	while (1);
#endif
}