#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
ifstream in("robots.in");
ofstream out("robots.out");
vector<vector<int>> com;
vector<vector<pair<int, int>>> a;
vector<vector<bool>> cycle;
int c = 1;
int dfs(vector<vector<int>> & vis, int x, int y, int t) {
	int tox = x + a[x][y].first;
	int toy = y + a[x][y].second;
	vis[x][y] = t;
	if (vis[tox][toy]) {
		com[x][y] = c++;
		cycle[x][y] = true;
		vis[x][y] = 0;
		return vis[tox][toy];
	}
	else {
		int res = 10000000;
		if (com[tox][toy] == 0) {
			res = dfs(vis, tox, toy, t + 1);
			if (res <= t)
				cycle[x][y] = true;
		}
		com[x][y] = com[tox][toy];
		vis[x][y] = 0;
		return res;
	}
}

pair<int, int> gch(char c) {
	switch (tolower(c)) {
	case 'n':
		return make_pair(-1, 0);
	case 's':
		return make_pair(1, 0);
	case 'e':
		return make_pair(0, 1);
	case 'w':
		return make_pair(0, -1);
	}
}

int main()
{
	int n, m;
	bool g;
	in >> n >> m >> g;
	com = vector<vector<int>>(n, vector<int>(m, 0));
	cycle = vector<vector<bool>>(n, vector<bool>(m, false));
	a = vector<vector<pair<int, int>>>(n, vector<pair<int, int>>(m));
	vector<vector<bool>> robot(n, vector<bool>(m, false));
	vector<vector<int>> vis(n, vector<int>(m, 0));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			char c;
			in >> c;
			a[i][j] = gch(c);
			robot[i][j] = isupper(c);
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (com[i][j] == 0) {
				dfs(vis, i, j, 1);
			}
		}
	}
	int count = 0;
	vector<int> colors(c - 1, 0);
	vector<int> cycles(c - 1, 0);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (cycle[i][j])
				cycles[com[i][j] - 1]++;
			if (robot[i][j])
				colors[com[i][j] - 1]++;
		}
	}
	for (int i = 0; i < c - 1; ++i) {
		count += min(colors[i], cycles[i]);
	}
	out << count;
}