#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<set>

using namespace std;
vector<int>r;
vector<vector<char> >u;
vector<int>rob;
vector<int>tm, used;
vector<int>cicler;
vector<int> p;
vector<int>pra1, pra2;
int perl = 0;
int x = 0;
int  z = 0;
int y = 1;
void dfs(int v)
{
	if (tm[v] != 0 && used[v] == 1)
	{
		pra1.push_back (y - tm[v]);
		tm[v] = y - tm[v];
		perl++;
		x = perl;
		used[v] = 2;
		return;
	}
	else
	{
		tm[v] = y;
		used[v] = 1;
	}
	if (rob[v] == 1)
		z++;
	y++;
	p.push_back(v);
	if(cicler[r[v]] != 0)
	{ 
		x = cicler[r[v]];
		return;
	}
	else
		dfs(r[v]);
}

int main()
{
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	int n, m, g;
	cin >> n >> m >> g;
	if (g == 1)
	{
		cout << 0;
		return 0;
	}
	rob.resize(n * m);
	r.resize(n * m);
	tm.resize(n * m);
	cicler.resize(n * m);
	used.resize(n * m);
	u.resize(n, vector<char>(m));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			cin >> u[i][j];
			if (u[i][j] == 'w' || u[i][j] == 'W')
				r[i * m + j]=(i*m + j - 1);
			if (u[i][j] == 's' || u[i][j] == 'S')
				r[i * m + j]=(i * m + m + j);
			if (u[i][j] == 'e' || u[i][j] == 'E')
				r[i * m + j]=(i*m + j + 1);
			if (u[i][j] == 'n' || u[i][j] == 'N')
				r[i * m + j]=(i * m - m + j);
			if (u[i][j] == 'W' || u[i][j] == 'N' || u[i][j] == 'E' || u[i][j] == 'S')
				rob[i * m + j] = 1;
		}
	for (int i = 0; i < n * m; i++)
	{
		if (used[i] == 0)
		{
			p.clear();
			x = 0;
			z = 0;
			y = 1;
			dfs(i);
			for (int j = 0; j < p.size(); j++)
				cicler[p[j]] = x;
			if (pra1.size() != pra2.size())
				pra2.push_back(z);
			else
				pra2[x - 1] += z;
		}
	}
	int ans = 0;
	for (int i = 0; i < pra2.size(); i++)
		ans += min(pra2[i], pra1[i]);
	cout << ans;
	return 0;
}