#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<iomanip>
#include<set>
#pragma warning(disable : 4996)

using namespace std;

vector<vector<long long> > resh(4000000, vector<long long>());
vector<vector<long long> > resh1(4000000, vector<long long>());
vector<long long> used(4000000);
vector<long long> used1(4000000);
vector<long long> usedp(4000000);
vector<long long> otv;
vector<vector<char> > mat(4000, vector<char>(4000));
long long h;
long long y;
long long po;

long long ver;
long long c;
long long n, m, g;


void dfs1(long long a) {
	usedp[a] = 1;
	if (mat[a/m][a%m] >= 'A' && mat[a/m][a%m] <= 'Z')
		ver++;
	for (long long i = 0; i < resh1[a].size(); i++) {
		if (usedp[resh1[a][i]] == 0)
			dfs1(resh1[a][i]);
	}
}


void dfs(long long a) {
	for (long long i = 0; i < resh[a].size(); i++) {
		if (used[resh[a][i]] == -1) {
			used[resh[a][i]] = a;
			dfs(resh[a][i]);
		}
		else {
			if (used1[resh[a][i]] != 1) {
				h = -1;
				po = resh[a][i];
			}
		}
		if (h == -1 && a != po) {
			otv.push_back(a);
			c++;
			used1[a] = 1;
			return;
		}
		if (a == po) {
			otv.push_back(a);
			c++;
			po = -1;
			h = 0;
			//used1[a] = 1;
		}
	}
	used1[a] = 1;
}

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

	cin >> n >> m >> g;

	for (long long i = 0; i < n; i++) {
		for (long long j = 0; j < m; j++) {
			cin >> mat[i][j];
		}
	}

	for (long long i = 0; i < n; i++) {
		for (long long j = 0; j < m; j++) {
			if ((mat[i][j] == 's' && i < n-1) || mat[i][j] == 'S') {
				resh[i*m + j].push_back((i + 1)*m + j);
				resh1[(i + 1)*m + j].push_back(i*m + j);
			}
			if ((mat[i][j] == 'n' && i > 0) || mat[i][j] == 'N') {
				resh[i*m + j].push_back((i - 1)*m + j);
				resh1[(i - 1)*m + j].push_back(i*m + j);
			}
			if ((mat[i][j] == 'w' && j > 0) || mat[i][j] == 'W') {
				resh[i*m + j].push_back(i*m + j - 1);
				resh1[i*m + j - 1].push_back(i*m + j);
			}
			if ((mat[i][j] == 'e' && j < m-1) || mat[i][j] == 'E') {
				resh[i*m + j].push_back(i*m + j + 1);
				resh1[i*m + j + 1].push_back(i*m + j);
			}
		}
	}

	y = 0;
	h = 0;
	po = -1;
	for (long long i = 0; i < n*m; i++)
		used[i] = -1;

	for (long long i = 0; i < n*m; i++) {
		ver = 0;
		c = 0;
		if (used[i] == -1) {
			dfs(i);
			if (c > 0) {
				for (long long j = 0; j < otv.size(); j++) {
					usedp[otv[j]] = 1;
				}
				for (long long j = 0; j < otv.size(); j++) {
					dfs1(otv[j]);
				}
				while (otv.size() > 0)
					otv.pop_back();
			}
			y += min(ver, c);
		}
	}

	cout << y;
	return 0;
}