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

using namespace std;

const int MAXN = 1000;
int mt[MAXN][MAXN];
int dp[MAXN][MAXN];
int cc[MAXN][MAXN];
bool rb[MAXN][MAXN];
int used[MAXN][MAXN];

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

vector<int> crb;
vector<int> cl;

int dfs(int x, int y, int d)
{
//    cout << x << ' ' << y << endl;
    int x1 = x + dx[mt[x][y]];
    int y1 = y + dy[mt[x][y]];
    used[x][y] = 1;
    dp[x][y] = d;
    int cn;
    if (used[x1][y1] == 1)
    {
        cn = cl.size();
        cl.push_back(d - dp[x1][y1] + 1);
        crb.push_back(0);
    }
    else
    {
        if (used[x1][y1] == 2)
            cn = cc[x1][y1];
        else
            cn = dfs(x1, y1, d + 1);
    }
    cc[x][y] = cn;
    used[x][y] = 2;
    if (rb[x][y])
        crb[cn]++;
    return cn;
}

int main()
{
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    int n, m, g, i, j;
    cin >> n >> m >> g;
    for (i = 0; i < n; i++)
    for (j = 0; j < m; j++)
    {
        char c;
        cin >> c;
        if (c == 'n' || c == 'N')
            mt[i][j] = 0;
        if (c == 'e' || c == 'E')
            mt[i][j] = 1;
        if (c == 's' || c == 'S')
            mt[i][j] = 2;
        if (c == 'w' || c == 'W')
            mt[i][j] = 3;
        if (c >= 'A' && c <= 'Z')
            rb[i][j] = true;
        else
            rb[i][j] = false;
        used[i][j] = 0;
        dp[i][j] = 0;
    }
//    for (i = 0; i < n; i++)
//    {
//        for (j = 0; j < m; j++)
//        {
//            cout << mt[i][j] << ' ';
//        }
//        cout << endl;
//    }
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < m; j++)
            if (used[i][j] == 0)
            dfs(i, j, 0);
    }
    int ans = 0;
    for (i = 0; i < cl.size(); i++)
    {
//        cout << cl[i] << ' ' << crb[i] << endl;
        ans += min(cl[i], crb[i]);
    }
    cout << ans;
    return 0;
}
