#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <memory.h>

#define rep(i, n) for (decltype(n) i = 0; i < n; i++)
#define dep(i, n) for (decltype(n) i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (decltype(b) i = a; i <= b; i++)
#define FORD(i, a, b) for (decltype(a) i = a; i >= b; i--)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()
typedef long long int64;
typedef long double ld;
using namespace std;

const int maxn = 1001;
char c[maxn][maxn];
int num_cyc[maxn][maxn];
vector<pair<int, int> > rob;
int rob_cyc[maxn * maxn];
int cyc_rob_cnt[maxn * maxn];
int cyclen[maxn * maxn];
bool used[maxn][maxn];
inline void go(int &x, int &y)
{
	if (c[x][y] == 'n')
		x--;
	else if (c[x][y] == 's')
		x++;
	else if (c[x][y] == 'e')
		y++;
	else if (c[x][y] == 'w')
		y--;
	else
		throw 1;
}

int main()
{
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	int n, m, g;
	cin >> n >> m >> g;
	rep(i, n)
	{
		string s;
		cin >> s;
		rep(j, m)
		{
			c[i][j] = s[j];
			if (c[i][j] >= 'A' && c[i][j] <= 'Z')
				c[i][j] = tolower(c[i][j]), rob.push_back({ i, j });
		}
	}
	int num = 1;
	rep(i, len(rob))
	{
		int x = rob[i].first, y = rob[i].second;
		deque<pair<int, int> > path;
		while (true)
		{
			if (num_cyc[x][y] != 0)
			{
				cyc_rob_cnt[num_cyc[x][y]]++;
				while (!path.empty())
					used[path.front().first][path.front().second] = 0, path.pop_front();
				break;
			}
			if (used[x][y])
			{
				while (path.front() != make_pair(x, y))
					used[path.front().first][path.front().second] = 0, path.pop_front();
				int cyc_num = num++;
				cyc_rob_cnt[cyc_num] = 1;
				cyclen[cyc_num] = len(path);
				while (!path.empty())
				{
					num_cyc[path.front().first][path.front().second] = cyc_num;
					used[path.front().first][path.front().second] = 0, path.pop_front();
				}
				break;
			}
			path.push_back({ x, y });
			used[x][y] = true;
			go(x, y);
		}
	}
	int ans = 0;
	FOR(i, 1, num)
		ans += min(cyc_rob_cnt[i], cyclen[i]);
	cout << ans << endl;
	return 0;
}