#include <iostream>
#include <cstdlib>
#include <queue>
#include <functional>
#include <algorithm>

using namespace std;

typedef long long int ll;

const int SIZE = 2000;

char s[SIZE][SIZE];
int type[SIZE][SIZE], l = 1;

int maxim[SIZE * SIZE], cnt[SIZE * SIZE];

void next(int &i, int &j, char c)
{
	if (c == 'n' || c == 'N')
		--i;
	else if (c == 's' || c == 'S')
		++i;
	else if (c == 'w' || c == 'W')
		--j;
	else
		++j;
}

/*int dfs(int x, int y, int col)
{
if (type[x][y] != 0)
return type[x][y];

int i = x, j = y;

next(i, j, s[i][j]);
type[x][y] = col;
return type[x][y] = dfs(i, j, col);
}*/

int dist;
int dfs(int x, int y, int col)
{
	if (type[x][y] != 0) {
		if (type[x][y] == col)
			type[x][y] = col + 1;

		return 0;
	}

	int i = x, j = y;

	type[x][y] = col;
	next(i, j, s[i][j]);

	int t = dfs(i, j, col) + 1;

	if (type[x][y] == col + 1)
		dist = t;

	if (type[i][j] < type[x][y])
		type[x][y] = type[i][j];

	return t;
}

bool rob(char c)
{
	return c == 'N' || c == 'S' || c == 'E' || c == 'W';
}

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

	int n, m, g;

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

	for (int i = 0; i < n; i++)
		gets_s(s[i]);

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (type[i][j] == 0) {
				dfs(i, j, l);
				maxim[l++] = dist;
				dist = 0;
			}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (rob(s[i][j]))
				cnt[type[i][j]]++;

	int sum = 0;
	for (int i = 1; i < l; i++)
		sum += min(maxim[i], cnt[i]);

	cout << sum << endl;

	return 0;
}