#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:512000000")
#include <iostream>
#include <algorithm>


typedef long long ll;


using namespace std;


#define TASK "robots"


char field[1005][1005];
int cycle_num[1005][1005];
int cycle_size[1005 * 1005];
int d[1005][1005];
int tcycle = 1;


int dfs(int i, int j, int dist) {
	if (cycle_num[i][j] != 0) {
		if (cycle_size[cycle_num[i][j]] == 0) {
			cycle_size[cycle_num[i][j]] = dist - d[i][j];
		}
		return cycle_num[i][j];
	}
	cycle_num[i][j] = tcycle;
	d[i][j] = dist;
	if (field[i][j] == 'n' || field[i][j] == 'N') {
		cycle_num[i][j] = dfs(i - 1, j, dist + 1);
	}
	if (field[i][j] == 's' || field[i][j] == 'S') {
		cycle_num[i][j] = dfs(i + 1, j, dist + 1);
	}
	if (field[i][j] == 'w' || field[i][j] == 'W') {
		cycle_num[i][j] = dfs(i, j - 1, dist + 1);
	}
	if (field[i][j] == 'e' || field[i][j] == 'E') {
		cycle_num[i][j] = dfs(i, j + 1, dist + 1);
	}
	return cycle_num[i][j];
}


bool is_robot(char c) {
	return 'A' <= c && c <= 'Z';
}


int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif // _DEBUG
	int n, m, g;
	cin >> n >> m >> g;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> field[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (dfs(i, j, 0) == tcycle) {
				tcycle++;
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (is_robot(field[i][j]) && cycle_size[cycle_num[i][j]] > 0) {
				ans++;
				cycle_size[cycle_num[i][j]]--;
			}
		}
	}
	cout << ans;
}