#include <fstream>
//#include <iostream>
#include <vector>

using namespace std;

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

struct cycle {
	int len, s;
	cycle(int len, int s): len(len), s(s) {}
};

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
const int MAXN = 1e3;
int n, m, g, t;
char a[MAXN][MAXN];
int color[MAXN][MAXN];
int loop[MAXN][MAXN];
int tim[MAXN][MAXN];
vector <cycle> c;

int min(int l, int r) {
	return l < r ? l : r;
}

void dfs(int i, int j) {
	tim[i][j] = t++;
	color[i][j] = GRAY;
	char d = a[i][j];
	int i_nxt = i + (d == 'S') + (d == 's') - (d == 'N') - (d == 'n');
	int j_nxt = j + (d == 'E') + (d == 'e') - (d == 'W') - (d == 'w');
	if (color[i_nxt][j_nxt] == WHITE)
		dfs(i_nxt, j_nxt);
	if (color[i_nxt][j_nxt] == BLACK)
		loop[i][j] = loop[i_nxt][j_nxt];
	else {
		loop[i][j] = c.size();
		c.push_back(cycle(tim[i][j] - tim[i_nxt][j_nxt] + 1, 0));
	}
	if (d >= 'A' && d <= 'Z' && loop[i][j] >= 0)
		++c[loop[i][j]].s;
	color[i][j] = BLACK;
}

int main() {
	cin >> n >> m >> g;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j) {
			cin >> a[i][j];
			loop[i][j] = -1;
		}
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			if (color[i][j] == WHITE)
				dfs(i, j);
	int ans = 0;
	for (int i = 0; i < c.size(); ++i)
		ans += min(c[i].len, c[i].s);
	cout << ans << endl;
	cin >> n;
	return 0;
}