#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<queue>

#pragma warning (disable:4996)

#define ll long long int
#define mp make_pair

using namespace std;

ll n, m, g, st[2000005], w, col[2000005], cyc[2000005], s[2000005];
char c[2005][2005];
vector<ll> v[2000005], p;

void f(ll x, ll y) {
	ll xx, yy;
	if (c[x][y] == 'N' || c[x][y] == 'n') {
		xx = x - 1;
		yy = y;
	}
	else {
		if (c[x][y] == 'S' || c[x][y] == 's') {
			xx = x + 1;
			yy = y;
		}
		else {
			if (c[x][y] == 'E' || c[x][y] == 'e') {
				xx = x;
				yy = y + 1;
			}
			else {
				xx = x;
				yy = y - 1;
			}
		}
	}
	v[x*m + y].push_back(xx*m + yy);
}

void dfs(ll q) {
	ll i;
	st[q] = 1;
	p.push_back(q);
	for (i = 0; i < v[q].size(); i++) {
		if (st[v[q][i]] == 0) {
			dfs(v[q][i]);
		}
		else {
			w = v[q][i];
		}
	}
}

void solve() {
	ll i, j, t = 0, k, ans = 0, e;
	for (i = 0; i < 2000005; i++) {
		col[i] = -1;
		st[i] = 0;
		cyc[i] = 0;
		s[i] = 0;
	}
	for (i = 0; i < n; i++) {
		cin >> c[i];
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			f(i, j);
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			if (st[i*m + j] == 0 && (ll)(c[i][j]) < 97) {
				p.clear();
				dfs(i*m + j);
				if (col[w] == -1) {
					col[w] = t;
					e = p.size();
					for (k = 0; k < e; k++) {
						if (p[k] == w) {
							s[col[w]] = e - k;
						}
						col[p[k]] = t;
					}
					t++;
				}
				else {
					for (k = 0; k < p.size(); k++) {
						col[p[k]] = col[w];
					}
				}
			}
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			if ((ll)(c[i][j]) < 97) {
				cyc[col[i*m + j]]++;
			}
		}
	}
	for (i = 0; i < 2000005; i++) {
		ans += min(s[i], cyc[i]);
	}
	printf("%I64d", ans);
	return;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#else
	freopen("robots.in", "rt", stdin);
	freopen("robots.out", "wt", stdout);
#endif
	scanf("%I64d%I64d%I64d", &n, &m, &g);
	solve();
	return 0;
}