#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1010;

int n, m, g;

int t, start;

int tin[MAXN][MAXN];
int cnt;

int dx[500], dy[500];
char f[MAXN][MAXN];
bool used[MAXN][MAXN];
int color[MAXN][MAXN];

int ans = 0;

pair <int, int> cycle[MAXN][MAXN];


void dfs(int x, int y)
{
	tin[x][y] = t++;
	int xx = x + dx[f[x][y]],
		yy = y + dy[f[x][y]];

	// printf("%d %d %d %d\n", x, y, xx, yy);

	pair <int, int> p;

	if (tin[xx][yy] == 0)
		dfs(xx, yy);
	else
	{
		if (tin[xx][yy] >= start)
			ans = max(ans, t - tin[xx][yy]);
	}

	// return make_pair(p.first, p.second + 1);	

}

int main()
{
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);

	scanf("%d%d%d", &n, &m, &g);
	assert(g == 0);

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
		{
			scanf(" %c ", &f[i][j]);
			if ('A' <= f[i][j] && f[i][j] <= 'Z')
				++cnt;
		}

	dx['S'] = dx['s'] = 1;
	dx['N'] = dx['n'] = -1;
	dy['E'] = dy['e'] = 1;
	dy['W'] = dy['w'] = -1;
	t = 1;


	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			if (tin[i][j] == 0)
			{
				start = t;
				dfs(i, j);
			}

	/*for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
			printf("%d ", tin[i][j]);
		printf("\n");
	}*/


	printf("%d\n", ans);



	return 0;
}