// A.cpp : Defines the entry point for the console application.
//

#include <fstream>
#include <vector>
#include <set>

using namespace std;

vector < vector<pair<int, int>>> a;
vector<vector<int>> r, b, w;
set<pair<int, int>> s;
set<pair<int, int>>::iterator it;
int t = 1;

int dfs(int x, int y)
{
	int i, j, dx, dy, k;
	b[x][y] = 1;
	if (b[x + a[x][y].first][y + a[x][y].second] == 0)
	{
		w[x][y] = dfs(x + a[x][y].first, y + a[x][y].second);
	}
	else if (b[x + a[x][y].first][y + a[x][y].second] == 1)
	{
		b[x][y] = 3;
		w[x][y] = t;
		i = x + a[x][y].first;
		j = y + a[x][y].second;
		k = 1;
		while (i != x || j != y)
		{
			b[i][j] = 3;
			w[i][j] = t;
			dx = a[i][j].first;
			dy = a[i][j].second;
			i += dx;
			j += dy;
			k++;
		}
		s.insert(make_pair(t, k));
		return t++;
	}
	else
		w[x][y] = w[x + a[x][y].first][y + a[x][y].second];
	if (b[x][y] != 3)
		b[x][y] = 2;
	return w[x + a[x][y].first][y + a[x][y].second];
}

int main()
{
	int n, m, i, j, g, x, y, k, ans = 0;
	char c;
	ifstream cin("robots.in");
	ofstream cout("robots.out");
	cin >> n >> m >> g;
	for (i = 0; i < n; i++)
	{
		a.push_back({});
		r.push_back({});
		b.push_back({});
		w.push_back({});
		for (j = 0; j < m; j++)
		{
			cin >> c;
			if ('a' <= c && c <= 'z')
				r[i].push_back(0);
			else
				r[i].push_back(1);
			if (c == 's' || c == 'S')
			{
				a[i].push_back(make_pair(1, 0));
			}
			else if (c == 'e' || c == 'E')
			{
				a[i].push_back(make_pair(0, 1));
			}
			else if (c == 'W' || c == 'w')
			{
				a[i].push_back(make_pair(0, -1));
			}
			else if (c == 'N' || c == 'n')
			{
				a[i].push_back(make_pair(-1, 0));
			}
			b[i].push_back(0);
			w[i].push_back(0);
		}
	}

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			if (!b[i][j])
				dfs(i, j);
		}
	}

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			if (r[i][j])
			{
				it = s.upper_bound(make_pair(w[i][j], -1));
				if (it != s.end() && it->first == w[i][j])
				{
					ans++;
					if (it->second > 1)
						s.insert(make_pair(w[i][j], it->second - 1));
					s.erase(it);
				}
			}
		}
	}
	/*for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			if (b[i][j] == 3)
				ans++;
		}
	}*/
	cout << ans << endl;
	cout.close();
}

