#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cassert>


using namespace std;


vector<vector<char>> g;
vector<vector<int>> cs, cd;
vector<vector<bool>> used;
vector<pair<int, int>> robots;
vector<int> cl;
map<char, int> dx, dy;
int ccs, ccl = -1;
int ccx = -1, ccy = -1;

void dfs(int x, int y) {
    used[x][y] = true;
    int mx = x + dx[g[x][y]];
    int my = y + dy[g[x][y]];
    if (used[mx][my]) {
        if (cs[mx][my] == -1) {
            cs[x][y] = ccs++;
            cd[x][y] = 0;
            ccx = mx;
            ccy = my;
            ccl = 1;
        } else {
            cs[x][y] = cs[mx][my];
            cd[x][y] = cd[mx][my] + 1;
        }
    } else {
        dfs(mx, my);
        if (ccl != -1) {
            cd[x][y] = 0;
            ++ccl;
            if (ccx == x && ccy == y) {
                cl.push_back(ccl);
                ccl = ccx = ccy = -1;
            }
        } else {
            cd[x][y] = cd[mx][my] + 1;
        }
        cs[x][y] = cs[mx][my];
    }
    if (g[x][y] == 'N' || g[x][y] == 'E' || g[x][y] == 'W' || g[x][y] == 'S') {
        robots.push_back(make_pair(x, y));
    }
}

int main() {
#ifndef LOCAL
    assert(freopen("robots.in", "r", stdin));
    assert(freopen("robots.out", "w", stdout));
#endif // LOCAL
    int n, m, tt;
    cin >> n >> m >> tt;
    assert(tt == 0);
    g.resize(n, vector<char>(m));
    cs.resize(n, vector<int>(m, -1));
    cd.resize(n, vector<int>(m, -1));
    used.resize(n, vector<bool>(m));
    dx['n'] = dx['N'] = -1;
    dx['s'] = dx['S'] = +1;
    dx['e'] = dx['E'] = 0;
    dx['w'] = dx['W'] = 0;
    dy['n'] = dy['N'] = 0;
    dy['s'] = dy['S'] = 0;
    dy['e'] = dy['E'] = +1;
    dy['w'] = dy['W'] = -1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> g[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (!used[i][j]) {
                dfs(i, j);
            }
        }
    }
    vector<int> cr(ccs);
    for (pair<int, int> r : robots) {
        ++cr[cs[r.first][r.second]];
    }
    int ans = 0;
    for (int i = 0; i < ccs; ++i) {
        ans += min(cl[i], cr[i]);
    }
    cout << ans << endl;

    return 0;
}
