#include <iostream>
#include <stdio.h>
#include <set>
#include <vector>
#include <string>

using namespace std;

const int maxn = 1005;
int a[maxn][maxn], used[maxn][maxn];
vector<string> v(maxn);
vector<pair<int, int> > cicl(maxn * maxn);
int ci = 1;

int dfs(int i, int j)
{
    //cout << i << " " << j << endl;
    if (used[i][j] == 1) {
        used[i][j] = 2;
        ++ci;
        return -1;
    }
    if (a[i][j] != 0) {
        return a[i][j];
    }
    used[i][j] = 1;
    int f;
    if (v[i][j] == 'N' || v[i][j] == 'n') {
        f = dfs(i - 1, j);
    }
    if (v[i][j] == 'E' || v[i][j] == 'e') {
        f = dfs(i, j + 1);
    }
    if (v[i][j] == 'S' || v[i][j] == 's') {
        f = dfs(i + 1, j);
    }
    if (v[i][j] == 'W' || v[i][j] == 'w') {
        f = dfs(i, j - 1);
    }
    if (v[i][j] == 'N' || v[i][j] == 'W' || v[i][j] == 'E' || v[i][j] == 'S') {
        if (f == -1) {
            ++cicl[ci].second;
        }
        else {
            ++cicl[f].second;
        }
    }
    if (f == -1) {
        ++cicl[ci].first;
        a[i][j] = ci;
    }
    else {
        a[i][j] = f;
    }
    if (used[i][j] == 2) {
        used[i][j] = 0;
        return ci;
    }
    used[i][j] = 0;
    return f;
}

signed main()
{
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    int n, m, g;
    cin >> n >> m >> g;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (a[i][j] == 0) {
                dfs(i, j);
            }
        }
    }
    int res = 0;
    for (int i = ci; i > 0; --i) {
        res += min(cicl[i].first, cicl[i].second);
    }
    cout << res << endl;
    return 0;
}
