#include <bits/stdc++.h>
using namespace std;

#define NAME "robots"

int main() {
#ifndef NO_FILES
	freopen(NAME".in", "r", stdin);
	freopen(NAME".out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	map<char, pair<int, int>> dc;
	dc['n'] = dc['N'] = {-1, 0};
	dc['s'] = dc['S'] = {1, 0};
	dc['e'] = dc['E'] = {0, 1};
	dc['w'] = dc['W'] = {0, -1};

	int n, m, g;
	cin >> n>> m>> g;
	vector<string> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	bool all_are_robots = true;
	for (int i = 0; i < n; ++i)
		all_are_robots &= all_of(a[i].begin(), a[i].end(), [](char c){return isupper(c);});

	auto inc = [&a, &dc](int &u, int &v) {
		auto p = dc[a[u][v]];
		u += p.first;
		v += p.second;
	};

	auto hasrobot = [&a](int x, int y) {
		return islower(a[x][y]);
	};


	if (all_are_robots) {
		vector<vector<int>> b(n, vector<int>(m, -1));
		int count = 0;
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < m; ++j)
				if (b[i][j] < 0) {
					++count;
					int x = i, y = j;
					while (b[x][y] < 0) {
						b[x][y] = 0;
						inc(x, y);
					}
					if (b[x][y] > 0) {
						int u = i, v = j;
						while (b[u][v] == 0) {
							b[u][v] = 1488228228;
							inc(u, v);
						}
					} else {
						int u = x, v = y;
						while (b[u][v] == 0) {
							b[u][v] = count;
							inc(u, v);
						}
						u = i; v = j;
						while (b[u][v] == 0) {
							b[u][v] = 1488228228;
							inc(u, v);
						}
					}
				}
		int ans = 0;
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < m; ++j)
				ans += 0 < b[i][j] and b[i][j] < 1488228228;

		cout << ans << endl;
	} else {
		vector<vector<int>> b(n, vector<int>(m, -1));
		vector<vector<int>> c(n, vector<int>(m, -1));
		vector<vector<int>> cn(n, vector<int>(m, -1));
		vector<vector<int>> ci(n, vector<int>(m, -1));
		int count = 0;
		vector<int> cycle(1, 0);
		vector<int> len(1, 0);
		vector<int> curi(1, 0);
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < m; ++j)
				if (b[i][j] < 0) {
					int x = i, y = j;
					int precycle = 0;
					int curlen = 0;
					while (b[x][y] < 0) {
						b[x][y] = 0;
						++precycle;
						inc(x, y);
					}
					int cx = x, cy = y;
					x = i; y = j;
					int cpc = 0;
					while (b[x][y] == 0) {
						c[x][y] = c[cx][cy] + precycle - (cpc++);
						cn[x][y] = cn[cx][cy];
						ci[x][y] = ci[cx][cy];
						inc(x, y);
					}

					if (b[x][y] > 0) {
						int u = i, v = j;
						while (b[u][v] == 0) {
							b[u][v] = 1488228228;
							inc(u, v);
						}
					} else {
						cycle.push_back(0);
						len.push_back(0);
						curi.push_back(0);
						++count;
						int u = x, v = y;
						while (b[u][v] == 0) {
							b[u][v] = count;
							ci[u][v] = len[count]++;
							cn[u][v] = count;
							inc(u, v);
						}
						u = i; v = j;
						while (b[u][v] == 0) {
							ci[u][v] = 0;
							b[u][v] = 1488228228;
							inc(u, v);
						}
					}
				}
		vector<tuple<int, int, int>> ans;
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < m; ++j)
				if (hasrobot(i, j)) {
					int ccn = cn[i][j];
					if (curi[ccn] == len[ccn])
						continue;
					ans.push_back(make_tuple(228, 228, 1488));
					curi[ccn]++;
				}
		cout << ans.size() << endl;
	}
}

