#pragma comment(linker, "/stack:25600000")

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

using namespace std;

#define MAXN 1004

bool visited[MAXN][MAXN];
int dir[MAXN][MAXN];
int rb[MAXN][MAXN];

int ansr = 0;
int cnt = 0;
int n, m, g;

vector<pair<int, int> > ans;

void funcan(int i, int j)
{
	if (rb[i][j] == 1)
		cnt++;
	visited[i][j] = true;
	if (dir[i - 1][j] == 2 && !visited[i - 1][j] && i != 0)
		funcan(i - 1, j);
	if (dir[i + 1][j] == 1 && !visited[i + 1][j] && i != (n + 1))
		funcan(i + 1, j);
	if (dir[i][j + 1] == 4 && !visited[i][j + 1] && j != (m + 1))
		funcan(i, j + 1);
	if (dir[i][j - 1] == 3 && !visited[i][j - 1] && j != 0)
		funcan(i, j - 1);  
	return;
}

void func(int i, int j)
{
	if (i == 0 || j == 0 || i == n + 1 || j == m + 1)
	{
		for (int z = 0; z < ans.size(); z++)
			funcan(ans[z].first, ans[z].second);
		if (cnt > 0)
			ansr++;
		ans.resize(0);
		return;
	}
	
	if (visited[i][j] == true)
	{
		int x = 0;
		for (x = 0; x < ans.size() && (ans[x].first != i || ans[x].second != j); x++);
		for (int z = 0; z < ans.size(); z++)
			funcan(ans[z].first, ans[z].second);
		if (cnt > ans.size() - x)
			ansr += ans.size() - x;
		else
			ansr += cnt;
		cnt = 0;
		ans.resize(0);
		return;
	}
	ans.push_back(make_pair(i, j));
	visited[i][j] = true;
	if (dir[i][j] == 2)
		func(i + 1, j);
	if (dir[i][j] == 1)
		func(i - 1, j);
	if (dir[i][j] == 3)
		func(i, j + 1);
	if (dir[i][j] == 4)
		func(i, j - 1);
	return;
}

int main()
{
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	cin >> n >> m >> g;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			char c;
			cin >> c;
			if (c == '\n' || c == '\r')
				j--;
			if (c == 'S')
			{
				rb[i][j] = 1;
				dir[i][j] = 2;
			}
			if (c == 'N')
			{
				rb[i][j] = 1;
				dir[i][j] = 1;
			}
			if (c == 'W')
			{
				rb[i][j] = 1;
				dir[i][j] = 4;
			}
			if (c == 'E')
			{
				rb[i][j] = 1;
				dir[i][j] = 3;
			}
			if (c == 's')
				dir[i][j] = 2;
			if (c == 'n')
				dir[i][j] = 1;
			if (c == 'w')
				dir[i][j] = 4;
			if (c == 'e')
				dir[i][j] = 3;
		}
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (!visited[i][j])
				func(i, j);
	cout << ansr;
	return 0;
}