#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;

#define lint long long int

#define C 1005

int n, m, c;

char f[C][C];

int loop[C][C];
int wh[C][C];

int haveLoop;

map<char, pair<int, int>> dir;

int xS, yS;
set<pair<int, int>> curPath, s0;

vector<int> loopSize;

void makeLoop(int x, int y, int ln, int xS, int yS)
{
	loop[x][y] = wh[x][y] = ln;
	loopSize[ln]++;
	int x0, y0;
	x0 = x + dir[f[x][y]].first;
	y0 = y + dir[f[x][y]].second;
	if (x0 == xS && y0 == yS)
		return;
	makeLoop(x0, y0, ln, xS, yS);
	
}

void makeWay(int x, int y, int ln)
{
	if (loop[x][y] != -1)
		return;
	wh[x][y] = ln;
	int x0, y0;
	x0 = x + dir[f[x][y]].first;
	y0 = y + dir[f[x][y]].second;
	makeWay(x0, y0, ln);
}

void go(int x, int y)
{
	if (curPath.find(make_pair(x, y)) != curPath.end())
	{
		loopSize.push_back(0);
		makeLoop(x, y, haveLoop++, x, y);
		makeWay(xS, yS, haveLoop - 1);
		return;
	}

	int x0, y0;
	x0 = x + dir[f[x][y]].first;
	y0 = y + dir[f[x][y]].second;
	if (loop[x0][y0] == -1) {
		if (wh[x0][y0] == -1) {
			curPath.insert(make_pair(x, y));
			go(x0, y0);
		}
		else
			wh[x][y] = wh[x0][y0];
	}
	else
	{
		wh[x][y] = loop[x0][y0];
		loop[x][y] = -1;
		makeWay(xS, yS, loop[x0][y0]);
	}
}

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

	cin >> n >> m >> c;

	haveLoop = 0;

	dir['w'] = dir['W'] = make_pair(0, -1);
	dir['e'] = dir['E'] = make_pair(0, 1);
	dir['n'] = dir['N'] = make_pair(-1, 0);
	dir['s'] = dir['S'] = make_pair(1, 0);


	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			cin >> f[i][j];
			loop[i][j] = -1;
			wh[i][j] = -1;
		}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			curPath = s0;
			xS = i;
			yS = j;
			if(loop[i][j] == -1)
			go(i, j);
		}

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

	cout << endl;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
		{
			cout << wh[i][j] << " ";
		}
		cout << endl;
	}

	cout << endl;

	for (int i = 0; i < loopSize.size(); i++)
		cout << loopSize[i] << " ";

	*/

	int res = 0;
	for (int i = 0; i < loopSize.size(); i++)
		res += loopSize[i];
	cout << res;

}