#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;
const int MAXN = 1001;
bool used[MAXN][MAXN];
int used1[MAXN][MAXN];
char g[MAXN][MAXN];
bool est[MAXN][MAXN];
int kol[MAXN][MAXN];
int n, m;
vector <pair <int, int> > ans;
vector <pair <int, int> > tp;

void dfs(int x, int y){
    used[x][y] = true;
    ans.push_back(make_pair(x, y));
    if ((y < m - 1) && (g[x][y + 1] == 'W') && (!used[x][y + 1])){
        dfs(x, y + 1);
    }
    if ((y > 0) && (g[x][y - 1] == 'E') && (used[x][y - 1] == false)){
        dfs(x, y - 1);
    }
    if ((x < n - 1) && (g[x + 1][y] == 'N') && (used[x + 1][y] == false)){
        dfs(x + 1, y);
    }
    if ((x > 0) && (g[x - 1][y] == 'S') && (used[x - 1][y] == false)){
        dfs(x - 1, y);
    }
}
int dfs1(int x, int y){
    used1[x][y] = 1;
    int sm = 0;
    if ((x < n - 1) && (g[x + 1][y] == 'N')){
        if (used1[x + 1][y] == 0){
            sm += dfs1(x + 1, y);
        }
        else if (used1[x + 1][y] == 2){
            sm += kol[x + 1][y];
        }
    }
    if ((x > 0) && (g[x - 1][y] == 'S')){
        if (used1[x - 1][y] == 0){
            sm += dfs1(x - 1, y);
        }
        else if (used1[x - 1][y] == 2){
            sm += kol[x - 1][y];
        }
    }
    if ((y > 0) && (g[x][y - 1] == 'E')){
        if (used1[x][y - 1] == 0){
            sm += dfs1(x, y - 1);
        }
        else if (used1[x][y - 1] == 2){
            sm += kol[x][y - 1];
        }

    }
    if ((y < m - 1) && (g[x][y + 1] == 'W')){
        if (used1[x][y + 1] == 0){
            sm += dfs1(x, y + 1);
        }
        else if (used1[x][y + 1] == 2){
            sm += kol[x][y + 1];
        }
    }

    kol[x][y] = sm + (!est[x][y]);
    used1[x][y] = 2;
    //if ((x == 1) && (y == 0)){
    //    cout << x << ' ' << y << ' ' << kol[x][y] << ' ' << ((x > 0) && (g[x - 1][y] == 'S')) << ' ' << used[x - 1][y] << endl;
    //}
    //else{
    //    cout << x << ' ' << y << ' ' << kol[x][y] << endl;
    //}
    return kol[x][y];
}

void top(int x, int y){
    used[x][y] = true;
    if ((g[x][y] == 'S') && (!used[x + 1][y])){
        top(x + 1, y);
    }
    else if ((g[x][y] == 'N') && (!used[x - 1][y])){
        top(x - 1, y);
    }
    else if ((g[x][y] == 'W') && (!used[x][y - 1])){
        top(x, y - 1);
    }
    else if ((g[x][y] == 'E') && (!used[x][y + 1])){
        top(x, y + 1);
    }
    tp.push_back(make_pair(x, y));
}

int main(){
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    //freopen("input.txt", "r", stdin);
    int v;
    cin >> n >> m >> v;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cin >> g[i][j];
            if (g[i][j] == 'w'){
                g[i][j] = 'W';
                est[i][j] = true;
            }
            if (g[i][j] == 'e'){
                g[i][j] = 'E';
                est[i][j] = true;
            }
            if (g[i][j] == 's'){
                g[i][j] = 'S';
                est[i][j] = true;
            }
            if (g[i][j] == 'n'){
                g[i][j] = 'N';
                est[i][j] = true;
            }
            used[i][j] = false;
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            for (int ii = 0; ii < n; ii++){
                for (int jj = 0; jj < m; jj++){
                    used[ii][jj] = false;
                }
            }
            ans.resize(0);
            dfs(i, j);
            kol[i][j] = ans.size();
           // cout << kol[i][j] << ' ';
        }
        //cout << endl;
    }
    ans.reserve(0);
    for (int ii = 0; ii < n; ii++){
        for (int jj = 0; jj < m; jj++){
            used[ii][jj] = false;
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            used[i][j] = false;
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (!used[i][j]){
                top(i, j);
            }
        }
    }
    //for (int i = 0; i < tp.size(); i++){
    //    cout << tp[i].first << ' ' << tp[i].second << endl;
    //}
    //cout << endl;
    //cout << endl;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            used[i][j] = false;
        }
    }
    int sm = 0;
    for (int i = tp.size() - 1; i >= 0; i--){
        pair <int, int> elem = tp[i];
        ans.resize(0);
        int x = elem.first;
        int y = elem.second;
        if (!used[x][y]){
            dfs(x, y);
            if (ans.size() > 1){
                sm += min(kol[x][y], (int)ans.size());
            }
        }


        //for (int i = 0; i < ans.size(); i++){
        //    cout << ans[i].first << ' ' << ans[i].second << endl;
        //}
        //cout << endl;
    }
    cout << sm;
}
