#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <time.h>
#include <algorithm>
#include <map>
	
#define forn(i, n) for (int i = 0; i < (n); i++)
#define fornn(i, q, n) for (int i = (q); i < (n); i++)
#define mp make_pair
#define times clock() * 1.0 / CLOCKS_PER_SEC
using namespace std;

typedef long long ll;

int solve();
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
	solve();
	return 0;
}

const int MAXN = 107;

int  color[MAXN][MAXN];
char G[MAXN][MAXN];
int n, m, g;
map<pair<int, int>, vector<pair<int, int> > > M;
map<vector<pair<int, int> >, int>  NS;
pair<int, int> P[MAXN][MAXN];
vector<vector<pair<int, int> > > cycle;

void dfs(int x, int y) {
	if (M[mp(x, y)].size() != 0) {
		NS[M[mp(x, y)]]++;
		return;
	}
	color[x][y] = 1;
	int nx = x, ny = y;

	if (G[x][y] == 'N') nx--;
	if (G[x][y] == 'W') ny--;
	if (G[x][y] == 'S') nx++;
	if (G[x][y] == 'E') ny++;

	if (color[nx][ny] == 1) {
		color[x][y] = 2;

		vector<pair<int, int> > T;

		int cx = x, cy = y;
		double t = times;
		while (P[cx][cy] != mp(nx, ny)) {
			assert(times - t < 0.5);
			T.push_back(mp(cx, cy));
			pair<int, int> cur = P[cx][cy];
			cx = cur.first;
			cy = cur.second;
		}
		T.push_back(mp(cx, cy));
		T.push_back(mp(nx, ny));
		forn(i, T.size()) {
			M[T[i]] = T;
		}
		NS[T]++;
		color[x][y] = 2;
		return;
	}
	else {
		P[nx][ny] = mp(x, y);
		dfs(nx, ny);
	}
	color[x][y] = 2;
}



int solve() {
	cin >> n >> m >> g;
	forn(i, n) {
		forn(j, m) {
			cin >> G[i][j];
		}
	}
	forn(i, n) {
		forn(j, m) {
			dfs(i, j);
		}
	}
	ll ans = 0;
	for (auto it = NS.begin(); it != NS.end(); it++) {
		ans += min(it->second, (int)it->first.size());
	}
	assert(ans != 0);
	cout << ans;
	return 0;
}