/* B_Robots */

#pragma comment(linker, "/STACK:268435456")

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <string>
#include <string.h>
#include <stdio.h>

using namespace std;

#define FOR(i, s, f) for (int i = (s); i < (f); ++i)
#define ROF(i, f, s) for (int i = (f) - 1; i >= (s); --i)
#define forn(i, f) for (int i = 0; i < (f); ++i)
#define rofn(i, f) for (int i = (f) - 1; i >= 0; --i)
#define forit(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())

typedef long long ll;
typedef long double ld;
typedef const int cint;
typedef const ll cll;
#define vi vector < int >

#define TASK "robots"

cint N = 1e3 + 3;
cint INF = 1e9;

char field[N * N];
int graph[N * N];

enum
{
	U = 'N',
	D = 'S',
	L = 'W',
	R = 'E',
	u = 'n',
	d = 's',
	l = 'w',
	r = 'e',

	W = 0,
	G = 1,
	B = 2,
};

int dr[10000], dc[10000];

int used[N * N];

bool on_cycle[N * N];
int n, m, g;

int color[N * N];

void is_on_cycle(int v);
void all_cycle(int v);
int dfs(int v, int cur_color);

int num_in_cycle[N * N];
int num_can_use[N * N];

int main()
{
	dr[U] = dr[u] = -1;
	dr[D] = dr[d] = 1;
	dr[L] = dr[l] = 0;
	dr[R] = dr[r] = 0;

	dc[L] = dc[l] = -1;
	dc[R] = dc[r] = 1;
	dc[U] = dc[u] = 0;
	dc[D] = dc[d] = 0;

	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);

	cin >> n >> m >> g;

	forn(i, n)
	{
		forn(j, m)
		{
			char a;
			cin >> a;
			int from = i * m + j;
			int to = (i + dr[a]) * m + j + dc[a];

			field[from] = a;

			graph[from] = to;
		}
	}

	memset(color, -1, sizeof(color));

	memset(used, 0, sizeof(used));
	forn(i, n * m)
	{
		if(used[i] == W)
			is_on_cycle(i);
	}

	memset(used, 0, sizeof(used));
	forn(i, n * m)
		if (on_cycle[i] && !used[i])
			all_cycle(i);

	memset(used, 0, sizeof(used));
	forn(i, n * m)
		if (!used[i] && color[i] == -1)
			dfs(i, i);

	int ans = 0;
	forn(i, n * m)
		ans += min(num_can_use[i], num_in_cycle[i]);

	cout << ans << endl;

/*
	int ans = 0;
	forn(i, n * m)
		if (on_cycle[i])
			++ans;

	cout << ans << endl;*/

	fclose(stdin);
	fclose(stdout);
	return 0;
}

int dfs(int v, int cur_color)
{
	used[v] = G;

	int to = graph[v];

	int ret_color;
	if (on_cycle[v])
	{
		ret_color = cur_color;
		color[v] = ret_color;

		if (!used[to])
			dfs(to, cur_color);
	}
	else
	{
		if (!used[to])
			ret_color = dfs(to, cur_color);
		else
			ret_color = color[to];

		color[v] = ret_color;
	}

	if (field[v] == U || field[v] == D || field[v] == L || field[v] == R)
		num_can_use[ret_color]++;
	if (on_cycle[v])
		num_in_cycle[ret_color]++;

	return ret_color;
}

void all_cycle(int v)
{
	used[v] = G;
	on_cycle[v] = true;

	int to = graph[v];
	on_cycle[to] = true;

	if (!used[to])
		all_cycle(to);
}

void is_on_cycle(int v)
{
	used[v] = G;

	int to = graph[v];

	if (used[to] == G)
		on_cycle[to] = true;
	else if(used[to] == W)
		is_on_cycle(to);

	used[v] = B;
}
