#include <stdio.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <iterator>
#include <utility>
#include <queue>
#include <deque>
#include <stack>

using namespace std;

const int MAXN = 1000;
char f[MAXN + 1][MAXN + 1];
map<char, pair<int, int> > mv;
int col[MAXN + 1][MAXN + 1], used[MAXN + 1][MAXN + 1], num[MAXN + 1][MAXN + 1], sz = 1, cnt[MAXN * MAXN + 1], can[MAXN * MAXN + 1], gt[MAXN * MAXN + 1], ans;
pair<int, int> pr[MAXN + 1][MAXN + 1];

char get(char x) {
	if ('a' <= x && x <= 'z')
		return x - 32;
	else
		return x;
}

void dfs(int x, int y) {
	used[x][y] = 1;
	int dx = mv[get(f[x][y])].first;
	int dy = mv[get(f[x][y])].second;
	if (!used[x + dx][y + dy]) {
		pr[x + dx][y + dy] = { x, y };
		dfs(x + dx, y + dy);
	}
	else if (used[x + dx][y + dy] == 1) {
		int stX = x + dx;
		int stY = y + dy;
		while (true) {
			num[x][y] = sz;
			cnt[sz]++;
			if ('A' <= f[x][y] && f[x][y] <= 'Z')
				can[sz]++;
			if (x == stX && y == stY)
				break;
			int a = x, b = y;
			x = pr[a][b].first;
			y = pr[a][b].second;
		}
		x = stX - dx;
		y = stY - dy;
		sz++;
	}
	used[x][y] = 2;
}

int dfs1(int x, int y, int calc = 0) {
	if (used[x][y]) {
		return used[x][y];
	}
	int dx = mv[get(f[x][y])].first;
	int dy = mv[get(f[x][y])].second;
	if ('A' <= f[x][y] && f[x][y] <= 'Z')
		calc++;
	if (!used[x + dx][y + dy])
		used[x][y] = dfs1(x + dx, y + dy, calc);
	else {
		if (used[x + dx][y + dy] != -1) {
			used[x][y] = used[x + dx][y + dy];
		}
	}
	if ('A' <= f[x][y] && f[x][y] <= 'Z')
		calc--;
	return used[x][y];
}

int main() {
	ios_base::sync_with_stdio(false);
	ifstream cin("robots.in");
	ofstream cout("robots.out");

	int n, m, g;
	cin >> n >> m >> g;
	mv['S'] = { 1, 0 };
	mv['N'] = { -1, 0 };
	mv['E'] = { 0, 1 };
	mv['W'] = { 0, -1 };
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> f[i][j];
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (!used[i][j])
				dfs(i, j);
		}
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			used[i][j] = num[i][j];
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (!used[i][j])
				used[i][j] = dfs1(i, j);
			if (used[i][j] != -1 && 'A' <= f[i][j] && f[i][j] <= 'Z')
				gt[used[i][j]]++;
		}
	}
	for (int i = 1; i <= n * m; i++)
		ans += min(gt[i] + can[i], cnt[i]);
	cout << ans << endl;
	return 0;
}