#include <fstream>

using namespace std;

typedef long long ll;

ifstream cin("robots.in");
ofstream cout("robots.out");

const int MAXN = 1000;

char field[MAXN][MAXN];
bool hasRobot[MAXN][MAXN];

int used[MAXN][MAXN];
int cUsed = 0;

pair<int, int> DFS(int i, int j) {
	// cout << i << ' ' << j << '\n';
	used[i][j] = cUsed;
	int ni = i, nj = j;
	if (field[i][j] == 'w') --nj;
	if (field[i][j] == 'e') ++nj;
	if (field[i][j] == 'n') --ni;
	if (field[i][j] == 's') ++ni;
	if (used[ni][nj] == cUsed) return make_pair(ni, nj);
	if (used[ni][nj]) return make_pair(-1, -1);
	return DFS(ni, nj);
}

int CycleLen(int i, int j) {
	used[i][j] = cUsed;
	int ni = i, nj = j;
	if (field[i][j] == 'w') --nj;
	if (field[i][j] == 'e') ++nj;
	if (field[i][j] == 'n') --ni;
	if (field[i][j] == 's') ++ni;
	if (used[ni][nj] == cUsed) return 1;
	return CycleLen(ni, nj) + 1;
}

bool reverseUsed[MAXN][MAXN];

int ReversedDFS(int i, int j) {
	reverseUsed[i][j] = 1;
	int res = 0;
	res += hasRobot[i][j];
	if (field[i + 1][j] == 'n' && !reverseUsed[i + 1][j])
		res += ReversedDFS(i + 1, j);
	if (field[i - 1][j] == 's' && !reverseUsed[i - 1][j])
		res += ReversedDFS(i - 1, j);
	if (field[i][j - 1] == 'e' && !reverseUsed[i][j - 1])
		res += ReversedDFS(i, j - 1);
	if (field[i][j + 1] == 'w' && !reverseUsed[i][j + 1])
		res += ReversedDFS(i, j + 1);
	return res;
}

int main() {
	int n, m, g;
	cin >> n >> m >> g;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			char c;
			cin >> c;
			if ('A' <= c && c <= 'Z') {
				hasRobot[i][j] = 1;
				c |= 32;
			}
			field[i][j] = c;
		}
	}
	int res = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (used[i][j]) continue;
			++cUsed;
			pair<int, int> cRoot = DFS(i, j);
			if (cRoot.first == -1) continue;
			++cUsed;
			// cout << "ROOT: " << cRoot.first << ' ' << cRoot.second << '\n';
			res += min(CycleLen(cRoot.first, cRoot.second), ReversedDFS(cRoot.first, cRoot.second));
		}
	}
	cout << res << '\n';
}
