#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <string>

using namespace std;

const int maxn = 2000;

int n, m, g;
int c[maxn][maxn];
int col[maxn][maxn];
bool used[maxn][maxn];
int it = 0;

pair <int, int> go(char c, int x, int y) {
	if (c == 'w' || c == 'W') {
		return make_pair(x, y - 1);
	} else if (c == 'e' || c == 'E') {
		return make_pair(x, y + 1);
	} else if (c == 'n' || c == 'N') {
		return make_pair(x - 1, y);
	} else if (c == 's' || c == 'S') {
		return make_pair(x + 1, y);
	}
}

vector <pair <int, int> > zikl[maxn];

int zikl_size[maxn];
int num_zikl[maxn];

int make_colour(int x, int y) {
	if (used[x][y]) {
		if (col[x][y] == 0) {
			it++;
			col[x][y] = it;
		}
		zikl[col[x][y]].push_back(make_pair(x, y));
		return col[x][y];
	} else {
		used[x][y] = true;
		int now = make_colour(go(c[x][y], x, y).first, go(c[x][y], x, y).second);
		col[x][y] = now;
		zikl[now].push_back(make_pair(x, y));
		return col[x][y];
	}
}

int main() {
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);

	scanf("%d %d %d", &n, &m, &g);

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;

		for (int j = 0; j < m; j++) {
			c[i][j] = s[j];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (col[i][j] == 0) {
				make_colour(i, j);
			}
		}
	}

	/*for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << col[i][j] << ' ';
		}
		cout << endl;
	}*/

	for (int i = 1; i <= it; i++) {
		for (int j = 0; j < (int)zikl[i].size(); j++) {
			if (zikl[i][j].first == zikl[i][0].first && zikl[i][j].second == zikl[i][0].second && j != 0) {
				zikl_size[i] = j;
				break;
			}
			//cout << zikl[i][j].first + 1 << ' ' << zikl[i][j].second + 1 << endl;
		}
		//cout << endl;
	}

	for (int i = 0; i < maxn; i++) {
		for (int j = 0; j < maxn; j++) {
			used[i][j] = false;
		}
	}

	/*for (int i = 1; i <= it; i++) {
		cout << zikl_size[i] << ' ';
	}

	cout << endl;*/

	for (int i = 1; i <= it; i++) {
		for (int j = 0; j < (int)zikl[i].size(); j++) {
			int x = zikl[i][j].first;
			int y = zikl[i][j].second;

			if (!used[x][y] && c[x][y] >= 'A' && c[x][y] <= 'Z') {
				used[x][y] = true;
				num_zikl[i]++;
			}
		}
	}

	/*for (int i = 1; i <= it; i++) {
		cout << num_zikl[i] << ' ';
	}

	cout << endl;*/

	int res = 0;

	for (int i = 1; i <= it; i++) {
		res += min(zikl_size[i], num_zikl[i]);
	}

	cout << res << endl;

	return 0;
}
/*
3 4 0
SSSS
EESW
ENWW
*/

/*
4 4 1
essS
Eess
Snww
EeWN
*/