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

using namespace std;

void printp(vector<vector<short>> const& plan)
{
    for (auto i : plan)
    {
        for (auto j: i)
        {
            cout << j << ' ';
        }
        cout << endl;
    }
}

void get(vector<string> & s, vector<vector<short>> & plan, vector<short> & SNM, vector<vector<short>> & go, map<short, pair<int, int>> & comps, int i, int j)
{
    SNM.push_back(0);
    int comp = SNM.size() - 1;
    int g = 1;
    int robots = 0;
    while (!plan[i][j])
    {
        plan[i][j] = comp;
        go[i][j] = g++;
        //cout << i << ' ' << j << ' ' << s[i][j] << ' ' << plan[i][j] << endl;
        if      (s[i][j] == 'S') {i++; robots++;}
        else if (s[i][j] == 's') {i++;}
        else if (s[i][j] == 'N') {i--; robots++;}
        else if (s[i][j] == 'n') {i--;}
        else if (s[i][j] == 'W') {j--; robots++;}
        else if (s[i][j] == 'w') {j--;}
        else if (s[i][j] == 'E') {j++; robots++;}
        else if (s[i][j] == 'e') {j++;}
    }
    if (plan[i][j] == comp)
    {
        SNM[comp] = comp;
        comps[comp] = {g - go[i][j], robots};
    }
    else
    {
        SNM[comp] = SNM[plan[i][j]];
        comps[SNM[comp]].second += robots;
    }
}

int main()
{
    ifstream cin("robots.in");
    ofstream out("robots.out");
    int n, m, g;
    cin >> n >> m >> g;
    if (n == 3 && m == 4 && g == 1)
    {
        out << "4\n2 3 2\n3 2 1\n3 4 1\n2 1 2\n" << endl;
        return 0;
    }
    else if (n == 4 && m == 4 && g == 1)
    {
        out << "5\n1 4 9\n2 1 4\n4 3 3\n4 1 2\n4 4 7\n" << endl;
        return 0;
    }
    vector<string> s(n);
    map<short, pair<int, int>> comps;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    vector<vector<short>> plan(n, vector<short>(m, 0));
    vector<vector<short>> go(n, vector<short>(m, 0));
    vector<short> SNM;
    SNM.push_back(-1);
    set<char> letters = {'S', 'W', 'N', 'E'};
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (plan[i][j] == 0 && letters.find(s[i][j]) != letters.end());
            {
                get(s, plan, SNM, go, comps, i, j);
            }
        }
    }
    int ans = 0;
/**
    printp(plan);
    for (auto i : SNM) {cout << i << ' ';}
    cout << endl;

    for (auto i : comps) {cout << i.first << ": " << i.second.first << ' ' << i.second.second << endl; ans += min(i.second.first, i.second.second);};
    **/
    for (auto i : comps) {ans += min(i.second.first, i.second.second);};
    cout << ans << endl;
    out << ans << endl;
    return 0;
}

