#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <set>
#include <map>

using namespace std;

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

typedef long long ll;

struct info {
    int robots = 0, length = 0;
    info() {}
};

map<char, pair<int, int>> arr;

struct point {
    int who = -1;
    char x;

    point(char x) : x(x) {}
    point() {}
};

int cnt = 0;

vector<vector<point>> g;
vector<vector<bool>> been;


vector<pair<int, int>> path;
vector<info> lol;
set<char> symb;

void donew() {
    info nx = info();

    auto pp = path.back();
    path.pop_back();

    int cnt_r = 0, l = -1;
    for (auto x : path) {

        g[x.first][x.second].who = cnt;

        char y = g[x.first][x.second].x;
        if (symb.find(y) != symb.end()) {
            cnt_r++;
        }

        if (l != -1)
            l++;

        if (x == pp)
            l = 1;
    }

    nx.length = l;
    nx.robots = cnt_r;

    lol.push_back(nx);
    cnt++;


    path.clear();
}

void append(int numb) {
    int cnt_r = 0, l = -1;
    for (auto x : path) {
        g[x.first][x.second].who = numb;

        char y = g[x.first][x.second].x;
        if (symb.find(y) != symb.end()) {
            cnt_r++;
        }
    }

    lol[numb].robots += cnt_r;
    path.clear();
}

void dfs(int i, int j) {
    been[i][j] = false;
    path.push_back(make_pair(i, j));


    if (been[i + arr[g[i][j].x].first][j + arr[g[i][j].x].second]) {
        dfs(i + arr[g[i][j].x].first, j + arr[g[i][j].x].second);
    } else {
        if (g[i + arr[g[i][j].x].first][j + arr[g[i][j].x].second].who == -1) {
            path.push_back(make_pair(i + arr[g[i][j].x].first, j + arr[g[i][j].x].second));

            donew();
            return;
        } else {
            append(g[i + arr[g[i][j].x].first][j + arr[g[i][j].x].second].who);
            return;
        }
    }
}

int main() {
    arr['s'] = make_pair(1, 0);
    arr['w'] = make_pair(0, -1);
    arr['e'] = make_pair(0, 1);
    arr['n'] = make_pair(-1, 0);

    arr['S'] = make_pair(1, 0);
    arr['W'] = make_pair(0, -1);
    arr['E'] = make_pair(0, 1);
    arr['N'] = make_pair(-1, 0);

    symb.insert('W');
    symb.insert('E');
    symb.insert('S');
    symb.insert('N');

    int n, m, p;
    in >> n >> m >> p;
    g.resize(n, vector<point> (m));
    been.resize(n, vector<bool> (m, true));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            char x;
            in >> x;

            g[i][j] = point(x);
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (been[i][j])
                dfs(i, j);
        }
    }

    int ans = 0;
    for (auto x : lol) {
        ans += min(x.robots, x.length);
    }

    cout << ans;

    return 0;
}
