#include<fstream>
#include<algorithm>
#include<string>
#include<set>
#include<vector>

using namespace std;

typedef long long ll;
const int maxn = 1000006;

int n, m;
int gr[maxn];
vector<int> grt[maxn];
bool arr[maxn];
bool vis[maxn];
string st;
int tim = 0;
int ciclcnt = -1;
vector<int> now;
vector<int> cicl[maxn];
int sxot[maxn];
set<int> nws;
int kakoicicl[maxn];

int dfsgrt(int v) {
	vis[v] = true;
	kakoicicl[v] = ciclcnt;
	int a = 0;
	if (arr[v]) a += 1;
	for (int i = 0; i < grt[v].size(); ++i) {
		if (nws.find(grt[v][i]) != nws.end()) a += 0;
		else a+=dfsgrt(grt[v][i]);
	}
	return a;
}

void do_cicl(int a) {
	ciclcnt += 1;
	cicl[ciclcnt].push_back(a);
	nws.clear();
	nws.insert(a);
	while (now[now.size() - 1] != a) {
		cicl[ciclcnt].push_back(now[now.size() - 1]);
		nws.insert(now[now.size() - 1]);
		now.pop_back();
	}
	int b = 0;
	for (int i = 0; i < cicl[ciclcnt].size(); ++i)
		b+=dfsgrt(cicl[ciclcnt][i]);
	sxot[ciclcnt] = b;
}

void dfs(int v) {
	vis[v] = true;
	now.push_back(v);
	nws.insert(v);
	if (nws.find(gr[v]) != nws.end()) {
		do_cicl(gr[v]);
		return;
	}
	else dfs(gr[v]);
	return;
}

int g;

int main() {
	ifstream cin("robots.in");
	ofstream cout("robots.out");
	ios_base::sync_with_stdio(false);
	cin >> n >> m >> g;
	getline(cin, st);
	int nw = -1;
	for (int i = 0; i < n; ++i) {
		getline(cin, st);
		for (int j = 0; j < m; ++j) {
			nw += 1;
			if (st[j] == 'N' || st[j] == 'S' || st[j] == 'E' || st[j] == 'W') arr[nw] = true; else arr[nw] = false;
			if (st[j] == 'N' || st[j] == 'n') gr[nw] = nw - m;
			if (st[j] == 'S' || st[j] == 's') gr[nw] = nw + m;
			if (st[j] == 'E' || st[j] == 'e') gr[nw] = nw + 1;
			if (st[j] == 'W' || st[j] == 'w') gr[nw] = nw - 1;
			grt[gr[nw]].push_back(nw);
		}
	}
	for (int i = 0; i < n*m; ++i)
		if (!vis[i]) {
			dfs(i);
			now.clear();
			nws.clear();
		}

	;
	int ans = 0;
	for (int i = 0; i <= ciclcnt; ++i) {
		ans += min(sxot[i], (int)cicl[i].size());
	}
	cout << ans;
	return 0;
}