#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define mkp make_pair
#define X first
#define Y second
#define next GNIL
const int maxn = 105;
char a[maxn][maxn];
pii next[maxn][maxn];
bool cycle[maxn][maxn];
int used[maxn][maxn];
int curt = 1;

pii dfs(int x, int y) {
    if (used[x][y] == curt) return mkp(x, y);
    used[x][y] = curt;
    return dfs(next[x][y].X, next[x][y].Y);
}

void dfs2(int x, int y) {
    if (used[x][y] == curt) return;
    used[x][y] = curt;
    cycle[x][y] = 1;
    dfs2(next[x][y].X, next[x][y].Y);
}

int main() {
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, g;
    cin >> n >> m >> g;
    if (g == 1) return 0;
    string s;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        for (int j = 0; j < m; ++j) {
            a[i][j] = s[j];
            if (a[i][j] == 'N') next[i][j] = mkp(i - 1, j);
            if (a[i][j] == 'S') next[i][j] = mkp(i + 1, j);
            if (a[i][j] == 'E') next[i][j] = mkp(i, j + 1);
            if (a[i][j] == 'W') next[i][j] = mkp(i, j - 1);
        }
    }
    for (int x = 0; x < n; ++x) {
        for (int y = 0; y < m; ++y) {
            pii C = dfs(x, y);
            ++curt;
            dfs2(C.X, C.Y);
            ++curt;
        }
    }
    int ans = 0;
    for (int x = 0; x < n; ++x) {
        for (int y = 0; y < m; ++y) {
            ans += cycle[x][y];
        }
    }
    cout << ans;
    return 0;
}
/*
3 4 0
SSSS
EESW
ENWW
*/

