#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;
long long n, m, g, x, y, z, ans;
vector<vector<vector<int> > > field;
vector<vector<int> > time;
vector<vector<int> > robot;
vector<vector<int> > cycle;
vector<vector<int> > used;
char c;
int dfs(int x, int y, int t){
    if (used[x][y] == 1){
        cycle[z][0] = t - time[x][y];
        cycle[z][1] = 1;
        cycle[z][2] = x;
        cycle[z][3] = y;
        used[x][y] = z;
        z += 1;
        return 0;
    }
    else{
        if (used[x][y] == 0){
            used[x][y] = 1;
            time[x][y] = t;
            dfs(x + field[x][y][0], y + field[x][y][1], t + 1);
            if (used[x][y] == 1){
                used[x][y] = 0;
            }
        }
        else{
            cycle[used[x][y]][1] += 1;
        }
    }
}
int main()
{
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    cin >> n >> m >> g;
    field.resize(n);
    time.resize(n);
    used.resize(n);
    for (int i = 0; i < n; i++){
        used[i].resize(m);
    }
    x = 0;
    y = 0;
    robot.resize(n * m);
    for(int i = 0; i < n; i++){
        field[i].resize(m);
        time[i].resize(m);
        for(int j = 0; j < m; j++){
            field[i][j].resize(2);
            cin >> c;
            if (c == 'S' || c == 's')
                field[i][j][0] = 1;
            else
                if (c == 'N' || c == 'n')
                    field[i][j][0] = -1;
                else
                    if (c == 'W' || c == 'w')
                        field[i][j][1] = -1;
                    else
                        field[i][j][1] = 1;
            if (c == 'S' || c == 'N' || c == 'W' || c == 'E'){
                robot[x].push_back(i);
                robot[x].push_back(j);
                x += 1;
            }
        }
    }
    cycle.resize(n * m + 100);
    for(int i = 0; i < n * m + 100; i++){
        cycle[i].resize(4);
    }
    z = 2;
    for(int i = 0; i < x; i++){
        dfs(robot[i][0], robot[i][1], 0);
    }
    ans = 0;
    for(int i = 2; i < z + 1; i++){
        ans += min(cycle[i][0], cycle[i][1]);
    }
    cout << ans;
    return 0;
}
