#include <bits/stdc++.h>

using namespace std;
vector < pair<int, int> > edg;
vector <int> used;
vector <int> kol;
int ans = 0;

dfs (int v, int gl){
 //   cout << v << "\n";
    kol[v] = gl;
    used[v] = 1;
    if (used[edg[v].first] == 1 && gl - kol[edg[v].first] + 1 != 2){
        ans += (gl - kol[edg[v].first]) + 1;
    }
    if (used[edg[v].first] == 0) dfs(edg[v].first, gl+1);
    used[v] = 2;
}

int main(){
   // freopen("robots.in", "r", stdin);
   // freopen("robots.out", "w", stdout);
    int n, m, g;
    cin >> n >> m >> g;
    edg.resize(n*m);
    used.resize(n*m, 0);
    kol.resize(n*m, 0);
    for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++){
        char c;
        cin >> c;
        if (c == 'S' || c == 's'){
            edg[n*i + j].first = n*(i+1) + j;
            if (c == 'S') edg[i].second = 0;
            else edg[i].second = 1;
        }
        if (c == 'N' || c == 'n'){
            edg[n*i + j].first = n*(i-1) + j;
            if (c == 'N') edg[i].second = 0;
            else edg[i].second = 1;
        }
        if (c == 'E' || c == 'e'){
            edg[n*i + j].first = n*i + j+1;
            if (c == 'E') edg[i].second = 0;
            else edg[i].second = 1;
        }
        if (c == 'W' || c == 'w'){
            edg[n*i + j].first = n*(i) + j-1;
            if (c == 'W') edg[i].second = 0;
            else edg[i].second = 1;
        }
    }
    for (int i = 0; i < n*m; i++)
        if (used[i] == 0) dfs(i, 0);
    cout << ans << "\n";
    return 0;
}
