#include <bits/stdc++.h>
#define mp make_pair
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
char a[1003][1003];
int color[1003][1003], xx[1000010], yy[1000010], cl[1003][1003], kl, hl[1003][1003], dck[1003][1003], tim, vn, vt, answ = 0;
bool cik[1003][1003];
vector<int> edx[1003][1003], edy[1003][1003];
vector<int> ansr, anss, anst;
void go(int &x, int &y, char c);
bool isbig(char c);
void dfs(int i, int j);
void dfs2(int i, int j);
int dfs3(int i, int j);
void dfs4(int i, int j);
void dfs5(int i, int j, int cur);
int main()
{
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    int n, m, g, i, j;
    cin >> n >> m >> g;
    /*if (g == 1)
        for(;;);*/
    for (i = 0; i < n; i++)
    {
        scanf("\n");
        for (j = 0; j < m; j++)
        {
            scanf("%c", &a[i][j]);
            if (isbig(a[i][j]))
                hl[i][j] = 1;
        }
    }

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

    for (i = 0; i < n; i++)
        for (j = 0; j < m; j++)
            color[i][j] = 0;

    for (i = 0; i < n; i++)
        for (j = 0; j < m; j++)
            if ((color[i][j] == 0) && (!cik[i][j]))
                dfs2(i, j);

    for (i = 0; i < n; i++)
        for (j = 0; j < m; j++)
            color[i][j] = 0;

    for (i = 0; i < n; i++)
        for (j = 0; j < m; j++)
            if (color[i][j] == 0)
                dfs3(i, j);

    for (i = 0; i < n; i++)
        for (j = 0; j < m; j++)
            color[i][j] = 0;

    for (i = 0; i < n; i++)
        for (j = 0; j < m; j++)
            if ((color[i][j] == 0) && (cik[i][j]))
                dfs4(i, j);

    cout << answ << endl;
    return 0;
}

void go(int &x, int &y, char c)
{
    //cout << x << ' ' << y << endl;
    if ((c == 'N') || (c == 'n'))
    {
        x--;
        return;
    }

    if ((c == 'S') || (c == 's'))
    {
        x++;
        return;
    }

    if ((c == 'E') || (c == 'e'))
    {
        y++;
        return;
    }

    if ((c == 'W') || (c == 'w'))
    {
        y--;
        return;
    }
}

bool isbig(char c)
{
    return ((c == 'E') || (c == 'W') || (c == 'N') || (c == 'S'));
}

void dfs(int i, int j)
{
    color[i][j] = 1;
    xx[kl++] = i;
    yy[kl - 1] = j;
    cl[i][j] = kl - 1;
    int x = i, y = j, p, vv;
    //cout << "sdfs\n";
    go(x, y, a[x][y]);
    //cout << "sdfs\n";
    if (color[x][y] == 0)
        dfs(x, y);
    else if (color[x][y] == 1)
    {
        vv = kl - cl[x][y];
        for (p = cl[x][y]; p < kl; p++)
        {
            cik[xx[p]][yy[p]] = 1;
            dck[xx[p]][yy[p]] = vv;
        }
    }

    color[i][j] = 2;
}

void dfs2(int i, int j)
{
    color[i][j] = 1;
    int x = i, y = j, p;
    go(x, y, a[x][y]);
    if ((color[x][y] == 0) && (!cik[x][y]))
        dfs2(x, y);
    edx[x][y].pb(i);
    edy[x][y].pb(j);
    color[i][j] = 2;
}

int dfs3(int i, int j)
{
    if (color[i][j] == 2)
        return hl[i][j];
    color[i][j] = 2;
    int p;
    for (p = 0; p < edx[i][j].size(); p++)
        hl[i][j] += dfs3(edx[i][j][p], edy[i][j][p]);
    return hl[i][j];
}

void dfs4(int i, int j)
{
    int p, x = i, y = j, vk;
    vn = dck[i][j];
    vt = vn;
    //cout << "----------" << endl;
    for(;;)
    {
        go(x, y, a[x][y]);
        //cout << x << ' ' << y << ' '  << i << ' ' << j << endl;
        color[x][y] = 2;
        vk = min(vn, hl[x][y]);
        answ += vk;
        vn -= vk;
        if ((x == i) && (y == j))
            break;
    }
}

/*int dfs5(int i, int j, int cur)
{
    if ((vn == 0) || (hl[i][j] == 0))
        return cur;

    int cur2, p;
    if (isbig(a[i][j]))
    {
        vn--;
        ansr.pb(i);
        anss.pb(j);
        cur2 = cur;
        anst.pb(cur);
    }
    else
        cur2--;

    for (p = 0; p < edx[i][j].size(); p++)
    {
        cur2 = dfs5(edx[i][j][p], edy[i][j][p], cur2);

    }
}*/


/*
3 4 0
SSSS
EESW
ENWW

3 4 1
SSSS
EeSW
ENwW

4 4 1
essS
Eess
Snww
EeWN
*/
