#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

vector<string> g;
vector<vector<int>> cycle;
vector<int> cycle_len = { 0 };
int next_cycle = 1;

inline bool robot_on(int y, int x) {
    return 'A' <= g[y][x] && g[y][x] <= 'Z';
}

inline void getdest(int y, int x, int &yy, int &xx) {
    switch(g[y][x]) {
    case 'e':
    case 'E':
        yy = y; xx = x+1;
        break;
    case 'W':
    case 'w':
        yy = y; xx = x-1;
        break;
    case 'S':
    case 's':
        yy = y+1; xx = x;
        break;
    case 'N':
    case 'n':
        yy = y-1; xx = x;
        break;
    default:
        assert(false);
    }
}

inline int get_cycle_len(int y, int x) {
    int a = 0;
    int yy = y, xx = x;
    do {
        ++a;
        getdest(yy, xx, yy, xx);
    } while(yy != y || xx != x);
    return a;
}

inline int dfs(int y, int x) {
    if(cycle[y][x] > 0) {
        return cycle[y][x];
    }
    if(cycle[y][x] == -1) {
        cycle_len.push_back(get_cycle_len(y, x));
        return cycle[y][x] = next_cycle++;
    }
    int yy, xx;
    getdest(y, x, yy, xx);
    cycle[y][x] = -1;
    return cycle[y][x] = dfs(yy, xx);
}

int main() {
    #define FNAME "robots"
    #ifndef LOCAL
    freopen(FNAME ".in", "r", stdin);
    freopen(FNAME ".out", "w", stdout);
    #endif
    int n, m, ggg;
    cin >> n >> m >> ggg;
    assert(ggg == 0);
    g.resize(n);
    for(int i = 0; i < n; ++i) cin >> g[i];
    cycle.assign(n, vector<int>(m));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            if(cycle[i][j] == 0) {
                dfs(i, j);
            }
        }
    }
    vector<int> rpc(cycle_len.size());
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            if(robot_on(i, j)) {
                rpc[cycle[i][j]]++;
            }
        }
    }
    int ans = 0;
    int sz = cycle_len.size();
    for(int i = 1; i < sz; ++i) {
        ans += min(cycle_len[i], rpc[i]);
    }
    cout << ans;
    return 0;
}
