//#include "stdafx.h"
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>

using namespace std;
int a, b, c, i, n, k, z,g, kol,j;
int m[5002][5002];
int com[5001001], kolv[5001001];
int m1[5001001],used[5001001], used1[5001001],m4[5001001], used2[5001001];
vector<int> r[5001001];
int x[5] = { 1,1,0,-1,0 };
int y[5] = { 1,0,-1,0,1 };
bool u;
void dfs(int x)
{
	if (x<1 || x>n*k)
		return;
	used[x] = kol;
	com[kol] += m1[x];
	for (int j = 0; j < (int) r[x].size(); j++)
		if (used[r[x][j]] == 0)
			dfs(r[x][j]);
}
void dfs1(int x)
{
	if (x<1 || x>n*k)
		return;
	used2[x] = 1;
	if (used2[m4[x]] == 1)
	{
		u = true;
		b = m4[x];
		kolv[used[x]]++;
		return;
	}
	else
		dfs1(m4[x]);
	if (u)
		kolv[used[x]]++;
	if (x == b)
		u = false;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	scanf("%d%d%d\n", &n, &k, &g);
	for (int i = 1; i <= n; i++)
	{
		for (int z = 1; z <= k; z++)
		{
			char ch;
			scanf("%c", &ch);
			if (ch == 'S' || ch == 'W' || ch == 'E' || ch == 'N')
				m1[(i-1)*k+z] = 1;
			if (ch == 'S' || ch == 's')
				m[i][z] = 1;
			else
				if (ch == 'W' || ch == 'w')
					m[i][z] = 2;
				else
					if (ch == 'N' || ch == 'n')
						m[i][z] = 3;
					else
						m[i][z] = 4;
			r[(i - 1)*k + z].push_back((i + x[m[i][z]] - 1)*k + (z+y[m[i][z]]));
			m4[(i - 1)*k + z] = r[(i - 1)*k + z][0];
		}
		scanf("\n");
	}
	for (int i = 1; i <= n; i++)
	{
		for (int z = 1; z <= k; z++)
		{
			if (m[i][z - 1] == 4)
				r[(i - 1)*k + z].push_back((i - 1)*k + z - 1);
			if (m[i - 1][z] == 1)
				r[(i - 1)*k + z].push_back((i - 2)*k + z);
			if (m[i][z + 1] == 2)
				r[(i - 1)*k + z].push_back((i - 1)*k + z + 1);
			if (m[i + 1][z] == 3)
				r[(i - 1)*k + z].push_back(i*k + z);
		}
	}
	long long res = 0;
	for (int i = 1; i <= n*k;i++)
		if (used[i] == 0 && m1[i]==1)
		{
			kol++;
			dfs(i);
		}
	for (int i = 1; i <= n*k;i++)
		if (used1[used[i]] == 0 && m1[i]==1)
		{
			used1[used[i]] = 1;
			b = 0;
			u = false;
			dfs1(i);
		}
	for (int i = 1; i <= kol; i++)
		res += min(com[i], kolv[i]);
	printf("%I64d", res);
	return 0;
}