#include <iostream>
#include <cstdlib>
#include <queue>
#include <functional>
#include <algorithm>

using namespace std;

typedef long long int ll;

const int SIZE = 2000;

char s[SIZE][SIZE];
int type[SIZE][SIZE], l = 1;

void next(int &i, int &j, char c)
{
	if (c == 'n' || c == 'N')
		--i;
	else if (c == 's' || c == 'S')
		++i;
	else if (c == 'w' || c == 'W')
		--j;
	else
		++j;
}

/*int dfs(int x, int y, int col)
{
	if (type[x][y] != 0)
		return type[x][y];

	int i = x, j = y;

	next(i, j, s[i][j]);
	type[x][y] = col;
	return type[x][y] = dfs(i, j, col);
}*/

int dist;
int dfs(int x, int y)
{
	if (type[x][y] != 0) {
		type[x][y] = 2;
		return 0;
	}

	int i = x, j = y;

	type[x][y] = 1;
	next(i, j, s[i][j]);
	
	int t = dfs(i, j) + 1;

	if (type[x][y] == 2)
		dist = t;

	return t;
}

int main()
{
#ifndef _CONSOLE
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
#else
	freopen("input.txt", "r", stdin);
#endif

	int n, m, g;

	scanf("%d %d %d\n", &n, &m, &g);

	for (int i = 0; i < n; i++)
		gets_s(s[i]);

	int max = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			dfs(i, j);

			if (dist > max)
				max = dist;
		}

	cout << max << endl;
}