#include <iostream>
#include <algorithm>
#include <vector>
#define MAXN 2000
#define ll long long
using namespace std;

int ky[] = {0, 1, 0, -1};
int kx[] = {-1, 0, 1, 0};
int bd[] = {2, 3, 0, 1};

int n, m, sum, g;
char c;
int used[MAXN * MAXN], was[MAXN * MAXN], num[MAXN * MAXN], timer = 1, t[MAXN * MAXN], tstart;
vector<int> ar[MAXN * MAXN];
int way[MAXN * MAXN];
int len, maxrob;
int cnt(int v)
{
    if (used[v])
        return 0;
    num[v] = was[v];
    used[v] = 1;
    for (auto i : ar[v])
        num[v] += cnt(i);
    return num[v];
}

int dfs(int v)
{
    //cerr << v << ' ';
    int res = 0;
    t[v] = timer++;
    if (used[way[v]] == 0)
    {
        if (t[way[v]] < tstart)
            res = dfs(way[v]);
        else
        {
            len = timer - t[way[v]];
            maxrob = cnt(way[v]);
        }
    }
    else
        return 0;
    //used[v] = 1;
}




int main()
{
    //cerr << ((int)'a') << ' ' << ((int)'A');
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    cin >> n >> m >> g;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        {
            cin >> c;
            if ((int)c < 97)
                was[i * m + j]++;
            if (c == 'N' || c == 'n')
            {
                way[i * m + j] = (i - 1) * m + j;
                ar[(i - 1) * m + j].push_back(i * m + j);
            }
            if (c == 'E' || c == 'e')
            {
                way[i * m + j] = i * m + j + 1;
                ar[i * m + j + 1].push_back(i * m + j);
            }
            if (c == 'S' || c == 's')
            {
                way[i * m + j] = (i + 1) * m + j;
                ar[(i + 1) * m + j].push_back(i * m + j);
            }
            if (c == 'W' || c == 'w')
            {
                way[i * m + j] = i * m + j - 1;
                ar[i * m + j - 1].push_back(i * m + j);
            }
        }
//    for (int i = 0; i < n * m; i++)
//        if (!used[i])
//            cnt(i);
    int res = 0;
    for (int i = 0; i < n * m; i++)
        if (!used[i])
        {
            tstart = timer;
            len = 0;
            maxrob = 0;
            dfs(i);
            res += min(len, maxrob);
            cerr << '\n';
        }
    cout << res << '\n';
    cerr << res << '\n';
    return 0;
}
