#include <bits/stdc++.h>

using namespace std;

int n, m, g, cyr[1010][1010];
char arr[1010][1010];
int color[1010][1010];

pair <int, int> ch;

int ans = 0;

bool flag = true;

void dfs1(int x, int y) {
    if (color[x][y] == 1) {
        ch = make_pair(x, y);
        color[x][y] = 2;
        return;
    }
    if (color[x][y] == 2) {
        flag = false;
        ch = make_pair(-1, -1);
        return;
    }
    color[x][y] = 1;
    if (arr[x][y] == 'S' || arr[x][y] == 's') {
        dfs1(x + 1, y);
        color[x][y] = 2;
    }
    if (arr[x][y] == 'N' || arr[x][y] == 'n') {
        dfs1(x - 1, y);
        color[x][y] = 2;
    }
    if (arr[x][y] == 'W' || arr[x][y] == 'w') {
        dfs1(x, y - 1);
        color[x][y] = 2;
    }
    if (arr[x][y] == 'E' || arr[x][y] == 'e') {
        dfs1(x, y + 1);
        color[x][y] = 2;
    }
   // cout << "   -   " << x << ", " << y << endl;
    color[x][y] = 2;
}

int cntt = 0;

int cru = 0, kl = 0;

int numb[1000005], kol[1000005];

void cnt(int x, int y, int f) {
    if (x == ch.first && y == ch.second && f == 1) {
        cyr[x][y] = cru;
        return;
    }
    cntt++;
    if (arr[x][y] == 'S' || arr[x][y] == 's') {
        if (arr[x][y] == 'S') {
            kl++;
            ans++;
        }
        cnt(x + 1, y, 1);
    }
    if (arr[x][y] == 'N' || arr[x][y] == 'n') {
        if (arr[x][y] == 'N') {
            kl++;
            ans++;
        }
        cnt(x - 1, y, 1);
    }
    if (arr[x][y] == 'W' || arr[x][y] == 'w') {
        if (arr[x][y] == 'W') {
            kl++;
            ans++;
        }
        cnt(x, y - 1, 1);
    }
    if (arr[x][y] == 'E' || arr[x][y] == 'e') {
        if (arr[x][y] == 'E') {
            kl++;
            ans++;
        }
        cnt(x, y + 1, 1);
    }
    cyr[x][y] = cru;
}

int sum = 0;
int cruu = 0;

void dfs2(int x, int y) {
    color[x][y] = 1;
    if (cyr[x][y] != 0) {
        cruu = cyr[x][y];
        ans += min(numb[cruu] - kol[cruu], sum);
        kol[cruu] += min(numb[cruu] - kol[cruu], sum);;
        return;
    }
    if (arr[x][y] == 'S' || arr[x][y] == 's') {
        if (arr[x][y] == 'S') {
            sum++;
        }
        dfs2(x + 1, y);
    }
    if (arr[x][y] == 'N' || arr[x][y] == 'n') {
        if (arr[x][y] == 'N') {
            sum++;
        }
        dfs2(x - 1, y);
    }
    if (arr[x][y] == 'W' || arr[x][y] == 'w') {
        if (arr[x][y] == 'W') {
            sum++;
        }
        dfs2(x, y - 1);
    }
    if (arr[x][y] == 'E' || arr[x][y] == 'e') {
        if (arr[x][y] == 'E') {
            sum++;
        }
        dfs2(x, y + 1);
    }
    cyr[x][y] = cruu;
}

int main() {
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    cin >> n >> m >> g;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> arr[i][j];
            color[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if (color[i][j] == 0) {
                ch = make_pair(-1, -1);
                flag = true;
                dfs1(i, j);
                if (ch != make_pair(-1, -1) && flag) {
                    cru++;
                    cntt = 0;
                    kl = 0;
                    cnt(ch.first, ch.second, 0);
                    numb[cru] = cntt;
                    kol[cru] = kl;
                }
            }
        }
    }
    //cout << ans << endl;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            color[i][j] = 0;
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if (color[i][j] == 0) {
                sum = 0;
                cruu = 0;
                dfs2(i, j);
            }
        }
    }
    cout << ans;
    return 0;
}
