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

using namespace std;

const int INF = 1000000000;

vector <int> g;
string table[1000];
vector <int> tin(1000000, INF);
vector <int> cycle(1000000, -1);
vector <char> robot(1000000, false);

int main()
{
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);

    int n, m;
    cin >> n >> m;
    int g_type, i, j;
    cin >> g_type;
    for(i = 0; i < n; i++)
    {
        cin >> table[i];
    }
    g.resize(n * m);

    //to graph
    for(i = 0; i < n; i++)
    {
        for(j = 0; j < m; j++)
        {
            if(table[i][j] == 'N' or table[i][j] == 'n')
            {
                g[i * m + j] = i * m - m + j;
                robot[i * m + j] = (table[i][j] == 'N');
            }
            else if(table[i][j] == 'W' or table[i][j] == 'w')
            {
                g[i * m + j] = i * m + j - 1;
                robot[i * m + j] = (table[i][j] == 'W');
            }
            else if(table[i][j] == 'E' or table[i][j] == 'e')
            {
                g[i * m + j] = i * m + j + 1;
                robot[i * m + j] = (table[i][j] == 'E');
            }
            else if(table[i][j] == 'S' or table[i][j] == 's')
            {
                g[i * m + j] = i * m + m + j;
                robot[i * m + j] = (table[i][j] == 'S');
            }
        }
    }

    //cycles
    int now_cycle = 0;
    map <int, pair <int, int> > cyc;
    int timer = 0;
    int now;
    for(i = 0; i < n * m; i++)
    {
        if(tin[i] == INF)
        {
            //cout << "aga " << i << endl;
            int met_robot = robot[i];
            vector <int> comp;
            comp.push_back(i);
            tin[i] = timer;
            timer++;
            now = g[i];
            while(tin[now] > 2000000)
            {
                //cout << "going " << now << endl;
                tin[now] = timer;
                timer++;
                comp.push_back(now);
                now = g[now];
                met_robot += (robot[now]);
            }
            if(tin[now] < tin[i])
            {
                for(j = 0; j < comp.size(); j++)
                    cycle[comp[j]] = cycle[now];
                cyc[cycle[now]].second += met_robot;
            }
            else
            {
                for(j = 0; j < comp.size(); j++)
                    cycle[comp[j]] = now_cycle;
                cyc[now_cycle] = {timer - tin[now], met_robot};
                //cout << "---newcycle " << timer - tin[now] << endl;
                now_cycle++;
            }
        }
    }

    //answer;
    int ans = 0;
    for(auto k: cyc)
    {
        ans += min(k.second.first, k.second.second);
    }
    cout << ans << endl;

    //check check check
    /*for(i = 0; i < n * m; i += m)
    {
        for(j = 0; j < m; j++)
            cout << g[i + j] << " ";
        cout << endl;
    }*/

    return 0;
}
