#pragma warning(disable:4996)
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<map>
#define ll long long int
using namespace std;

int n, m, TEST,s[1007][1007],num[1007][1007],fr=0,sz[500007],good;
char c[1007][1007];
vector<pair<int,int>>v[500007];

pair<int, int>deep(int x, int y) {
	pair<int, int>tmp;
	int a, b;
	s[x][y] = -2;
	if (c[x][y] == 'w'||c[x][y]=='W') {
		a = 0;
		b = -1;
	}
	else if (c[x][y] == 'e' || c[x][y] == 'E') {
		a = 0;
		b = 1;
	}
	else if (c[x][y] == 'n' || c[x][y] == 'N') {
		a = -1;
		b = 0;
	}
	else if (c[x][y] == 's' || c[x][y] == 'S') {
		a = 1;
		b = 0;
	}
	if (s[x + a][y + b] == -2) {
		s[x + a][y + b] = -3;
		s[x][y] = 0;
		num[x][y] = fr;
		sz[fr] = 1;
		good = 1;
		if (c[x][y] >= 'A'&&c[x][y] <= 'Z')v[fr].push_back(make_pair(x, y));
		fr++;
		return make_pair(fr-1, 0);
	}
	else if (s[x + a][y + b] == -1) {
		tmp=deep(x + a, y + b);
		num[x][y] = tmp.first;
		sz[tmp.first] += good;
		if (c[x][y] >= 'A'&&c[x][y] <= 'Z')v[num[x][y]].push_back(make_pair(x, y));
		if (s[x][y] == -3) {
			good = 0;
		}
		s[x][y] = tmp.second+1;
		return make_pair(num[x][y], s[x][y]);
	}
	else {
		s[x][y] = s[x + a][y + b] + 1;
		num[x][y] = num[x + a][y + b];
		if (c[x][y] >= 'A'&&c[x][y] <= 'Z')v[num[x][y]].push_back(make_pair(x, y));
		return make_pair(num[x][y], s[x][y]);
	}
}

void sol() {
	int i, j;
	scanf("%d%d%d\n", &n, &m, &TEST);
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			c[i][j] = getchar();
		}
		getchar();
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			s[i][j] = -1;
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			if ((c[i][j]>='A'&&c[i][j]<='Z')&&s[i][j] == -1) {
				deep(i,j);
			}
		}
	}
	n = n;
	int ans = 0;
	for (i = 0; i < fr; i++) {
		ans += min(sz[i], (int)v[i].size());
	}
	printf("%d", ans);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	freopen("castle.in", "r", stdin);
	freopen("castle.out", "w", stdout);
#endif
	sol();
	return 0;
}