// B_WRO.cpp : Defines the entry point for the console application.
//

#include <fstream>
#include <vector>

using namespace std;

ifstream fin("robots.in");
ofstream fout("robots.out");

int n, m, g;
long long ans = 0;
vector <int> path, cur, tocyc;
vector <bool> vis, used, look;
vector <pair <int, int> > cyc;
vector <vector <int> > fre;

/*int dfs(int v, int move, int fir)
{
	vis[v] = true;

	if (path[v] == fir)
		return move + 1;
	if (vis[path[v]])
		return -1;
	return dfs(path[v], move + 1, fir);
}*/

pair <int, int> dfs(int v)
{
	if (tocyc[v] != -1)
		return make_pair(0, tocyc[v]);
	auto p = dfs(path[v]);
	if (cur[v] == 1)
		p.first++;
	tocyc[v] = p.second;
	return p;
}

int main()
{
	fin >> n >> m >> g;

	path.clear();
	path.resize(n * m, 0);
	cur = path;
	cyc.clear();
	used.clear();
	used.resize(n * m, false);
	fre.clear();
	tocyc.clear();
	tocyc.resize(n * m, -1);

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			char c;
			fin >> c;
			int ind = i * m + j;
			if (c == 'S' || c == 's')
				path[ind] = ind + m;
			if (c == 'N' || c == 'n')
				path[ind] = ind - m;
			if (c == 'W' || c == 'w')
				path[ind] = ind - 1;
			if (c == 'E' || c == 'e')
				path[ind] = ind + 1;
			if (c == 'N' || c == 'S' || c == 'W' || c == 'E')
				cur[ind] = 1;
		}
	}

	for (int i = 0; i < n * m; i++)
	{
		if (used[i])
			continue;
		vis.clear();
		vis.resize(n * m, false);
		//int res = dfs(i, 0, i);
		int p = path[i];
		vis[i] = true;
		int res = 1;
		while (p != i)
		{
			vis[p] = true;
			if (vis[path[p]] && path[p] != i)
				break;
			res++;
			p = path[p];
		}
		if (p != i)
			res = -1;
		if (res != -1)
		{
			cyc.push_back(make_pair(i, res));
			vector <int> fred;
			fred.clear();
			used[i] = true;
			if (cur[i] == 0)
				fred.push_back(i);
			tocyc[i] = cyc.size() - 1;
			int p = path[i];
			while (p != i)
			{
				used[p] = true;
				tocyc[p] = cyc.size() - 1;
				if (cur[p] == 0)
					fred.push_back(p);
				p = path[p];
			}
			fre.push_back(fred);
		}
	}

	look.clear();
	look.resize(n * m, false);

	for (int i = 0; i < n * m; i++)
	{
		if (used[i])
			continue;
		int p = i;
		auto pp = dfs(p);
		int cnt = pp.first;

		/*while (tocyc[p] == -1)
		{
			if (cur[p] == 1 && !look[p])
				cnt++;
			look[p] = true;
			p = path[p];
		}
		/*if (cur[p] == 1 && !look[p])
			cnt++;
		look[p] = true;*/
		if (cnt >= fre[pp.second].size())
			fre[pp.second].clear();
		else
			fre[pp.second].resize(fre[pp.second].size() - cnt);
	}

	for (int i = 0; i < cyc.size(); i++)
		ans += cyc[i].second - fre[i].size();

	fout << ans;
		
	return 0;
}

