#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;

const ll N = 1e3 + 1;

char a[N][N];
int used[N][N], dist[N][N], col[N][N], len[N][N];
vector <pair <int, int> > g[N][N], revg[N][N];

void dfs(int x, int y, int cur, int dst) {
    used[x][y] = 1;
    col[x][y] = cur;
    dist[x][y] = dst;
    fr(i, g[x][y].size()) {
        pair <int, int> to = g[x][y][i];
        if (col[to.first][to.second] > 0 && col[to.first][to.second] != cur)
            continue;
        if (used[to.first][to.second] == 1) {
            len[x][y] = dst - dist[to.first][to.second] + 1;
            continue;
        }
        if (!used[to.first][to.second])
            dfs(to.first, to.second, cur, dst + 1);
    }
    used[x][y] = 2;
}

int dfs2(int x, int y) {
    int ans = 0;
    if (isupper(a[x][y]))
        ans = 1;
    used[x][y] = 1;
    fr(i, revg[x][y].size()) {
        pair <int, int> to = revg[x][y][i];
        //if (!used[to.first][to.second])
        //    ans += isupper(a[to.first][to.second]);
        if (!used[to.first][to.second])
            ans += dfs2(to.first, to.second);
    }
    return ans;
}

int main() {
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    int n, m, g1;
    cin >> n >> m >> g1;
    fr(i, n)
        fr(j, m)
            cin >> a[i][j];
    fr(i, n)
        fr(j, m) {
            if (toupper(a[i][j]) == 'N')
                g[i][j].pb(mp(i - 1, j));
            if (toupper(a[i][j]) == 'S')
                g[i][j].pb(mp(i + 1, j));
            if (toupper(a[i][j]) == 'W')
                g[i][j].pb(mp(i, j - 1));
            if (toupper(a[i][j]) == 'E')
                g[i][j].pb(mp(i, j + 1));
        }

    fr(i, n)
        fr(j, m)
            fr(k, g[i][j].size()) {
                pair <int, int> to = g[i][j][k];
                revg[to.first][to.second].pb(mp(i, j));
            }

    int cur = 1;
    fr(i, n)
        fr(j, m)
            if (!used[i][j])
                dfs(i, j, cur++, 1);

    int ans = 0;

    fr(i, n)
        fr(j, m)
            used[i][j] = 0;

    fr(i, n)
        fr(j, m)
            if (len[i][j] && !used[i][j]) {
                int cnt1 = dfs2(i, j);
                ans += min(cnt1, len[i][j]);
            }
    cout << ans;
}
