#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

ifstream in("robots.in");
ofstream out("robots.out");

vector <vector <pair<int, int> > > visited;
vector <vector <char> > gr;
vector <pair <int, int> > com;

int dfs(int kn, int km, int dep, int comp){
    visited[kn][km] = make_pair(comp, dep);
    int nkn = kn, nkm = km;
    if (gr[kn][km] == 'N' || gr[kn][km] == 'n'){
        nkn--;
    }
    else if (gr[kn][km] == 'S' || gr[kn][km] == 's') nkn++;
    else if (gr[kn][km] == 'W' || gr[kn][km] == 'w') nkm--;
    else nkm++;
    if (visited[nkn][nkm].first != -1){
        if (comp == visited[nkn][nkm].first){
            com.push_back(make_pair(dep - visited[nkn][nkm].second + 1, 1));
            return -1;
        }
        else {
            com[visited[nkn][nkm].first].second += 1;
            visited[kn][km].first = visited[nkn][nkm].first;
            return visited[nkn][nkm].first;
        }
    }
    else {
        int kek = dfs(nkn, nkm, dep + 1, comp);
        if (kek != -1){
            visited[kn][km].first = kek;
        }
        return kek;
    }
}

int main(){
    int n, m, g, k, nwcm = 0;
    in >> n >> m >> g;
    visited.resize(n);
    gr.resize(n);
    for (int i = 0; i < n; i++){
        char tin;
        visited[i].resize(m);
        gr[i].resize(m);
        for (int j = 0; j < m; j++){
            in >> gr[i][j];
            visited[i][j] = make_pair(-1, -1);
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (visited[i][j].first != -1){
                com[visited[i][j].first].second += 1;
            }
            else if (gr[i][j] == 'N' || gr[i][j] == 'W' || gr[i][j] == 'E' || gr[i][j] == 'S'){
                int kyk = dfs(i, j, 0, nwcm);
                if (kyk == -1){
                    nwcm++;
                }
            }
        }
    }
    int res = 0;
    for (int i = 0; i < (int) com.size(); i++){
        res += min(com[i].first, com[i].second);
    }
    /*for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cout << visited[i][j].first << " ";
        }
        cout << endl;
    }*/
    out << res;
}
