#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < n; i++)
#define sz(a) (int)a.size()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
const int MAXN = 1005;
const string NAME = "robots";

char field[MAXN][MAXN];
int used[MAXN][MAXN];
int tin[MAXN][MAXN];
int cl[MAXN][MAXN];
int color;
int timer;
int szc[MAXN * MAXN];
bool orac;
int n, m;

bool check(int i, int j)
{
	return 0 <= i && i < n && 0 <= j && j < m;
}

void dfs(int i, int j)
{
	tin[i][j] = timer++;
	used[i][j] = 1;

	int ni, nj;
                           
	if (field[i][j] == 'w' || field[i][j] == 'W')
	{
		ni = i;
		nj = j - 1;
	}

	if (field[i][j] == 'e' || field[i][j] == 'E')
	{
		ni = i;
		nj = j + 1;
	}

	if (field[i][j] == 's' || field[i][j] == 'S')
	{
		ni = i + 1;
		nj = j;
	}

	if (field[i][j] == 'n' || field[i][j] == 'N')
	{
		ni = i - 1;
		nj = j;
	}

	assert(check(ni, nj));
	
	if (used[ni][nj] == 0)
		dfs(ni, nj);
	else if (used[ni][nj] == 1)
	{
		szc[color] = tin[i][j] - tin[ni][nj] + 1;
		cl[ni][nj] = color++;
	} 
        
        cl[i][j] = cl[ni][nj];

	used[i][j] = 2;
}

int main()
{
#ifndef LOCAL                                        
	freopen((NAME + ".in").c_str(), "rt", stdin);
	freopen((NAME + ".out").c_str(), "wt", stdout);
#endif	

	cin >> n >> m >> orac;

#ifndef LOCAL
	assert(!orac);
#endif

	forn(i, n)
		forn(j, m)
			cl[i][j] = -1;


	forn(i, n)
		forn(j, m)
			cin >> field[i][j];

	forn(i, n)
		forn(j, m)
			if (used[i][j] == 0)
			{
				dfs(i, j);
			}

	forn(i, n)
		forn(j, m)
			assert(cl[i][j] != -1);

	ll res = 0;
	forn(i, n)
		forn(j, m)
		{
			if ('A' <= field[i][j] && field[i][j] <= 'Z')
			{
				if (szc[cl[i][j]])
				{
					res++;
					szc[cl[i][j]]--;
				}  
			}          
		}
	cout << res;
	return 0;
}