#include <bits/stdc++.h>

using namespace std;

enum Dir {
    North, South, East, West
};

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

int idx(int i, int j) {
    return i * 1000 + j;
}

int idx(pair<int, int> i) {
    return idx(i.first, i.second);
}

Dir matrix[1000000];

pair<int, int> next(pair<int, int> i) {
    switch (matrix[idx(i)]) {
    case North:
        i.first--;
        break;
    case South:
        i.first++;
        break;
    case West:
        i.second--;
        break;
    case East:
        i.second++;
        break;
    }
    return i;
}

//unions stuff
pair<int, int> _p[1000000];
int robs[10000000]; //inactive robots in nodes connected to each union

pair<int, int>& p(pair<int, int> i) {
    return _p[idx(i.first, i.second)];
}

pair<int, int>& p(int i, int j) {
    return _p[idx(i, j)];
}


pair<int, int> un(int i, int j) {
    auto par = p(i, j);
    //cout << "unen" << i << ' ' << j << ' ' << par.first << ' ' << par.second << endl;
    if( par.first == i && par.second == j)
        return {i, j};
    return p(i, j) = un(par.first, par.second);
}

//union
pair<int, int> un(pair<int, int> l) {
    int i = l.first, j = l.second;
    return un(i, j);
}

void unite(pair<int, int> l, pair<int, int> r) {
    if(un(l) != un(r)) {
        robs[idx(un(l))] += robs[idx(un(r))];
        //cout << un(l).first << ' ' << un(l).second << endl;
        //cout << p(un(l)).first << ' ' << p(un(l)).second << endl;
        p(r) = un(l);
        //cout << endl;
        //cout << r.first << ' ' << r.second << ' ' << p(r).first << ' ' << p(r).second << ' ' << un(r).first << ' ' << un(r).second << endl;
        assert(un(l).first == un(r).first && un(l).second == un(r).second);
    }
}

//end union stuff

bool visited[1000000];
int possible_robots[10000000]; //length of a cycle in each union
int counter = 0;

//returns coordinates of a node in a cycle
pair<int, int> depth(pair<int, int> i) {
    if(visited[idx(i)]) return i;
    visited[idx(i)] = true;
    int _cntr = counter;
    counter++;
    auto nxt = next(i);
    //cout << 'k' << i.first << '/' << i.second << ' ' << nxt.first << '/' << nxt.second << endl;
    unite(nxt, i);
    auto u1 = un(i);
    auto u2 = un(nxt);
    //cout << 'u' << u1.first << '/' << u1.second << ' ' << u2.first << '/' << u2.second << endl;
    auto ret = depth(nxt);
    if(i == ret) {
        possible_robots[idx(un(i))] += counter - _cntr;
    }
    return ret;
}

int main() {
    fill(visited, visited + 1000000, false);
    fill(robs, robs + 10000000, 0);
    fill(possible_robots, possible_robots + 10000000, 0);
    for(int i = 0; i < 1000; i++)
        for(int j = 0; j < 1000; j++)
            p({i, j}) = {i, j};
    int n, m, g;
    inp >> n >> m >> g;

    for(int i = 0; i < n; i++) {
        string s;
        inp >> s;
        for(int j = 0; j < m; j++) {
            char c = s[j];
            switch (c) {
            case 'N':
                robs[idx(i, j)]++;
            case 'n':
                matrix[idx(i, j)] = North;
                break;
            case 'S':
                robs[idx(i, j)]++;
            case 's':
                matrix[idx(i, j)] = South;
                break;
            case 'E':
                robs[idx(i, j)]++;
            case 'e':
                matrix[idx(i, j)] = East;
                break;
            case 'W':
                robs[idx(i, j)]++;
            case 'w':
                matrix[idx(i, j)] = West;
                break;
            }
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(visited[idx(i, j)]) continue;
            counter = 0;
            depth({i, j});
        }
    }
    //analyzing the unions and counting the possible robots
    int totals = 0;
    bool analyzed[1000000];
    fill(analyzed, analyzed + 1000000, false);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(analyzed[idx(un(i, j))]) continue;
            analyzed[idx(un(i, j))] = true;
            totals += min(possible_robots[idx(un(i, j))], robs[idx(un(i, j))]);
        }
    }
    outp << totals;
    return 0;
}
