#include<bits/stdc++.h>
using namespace std;

#define xx first
#define yy second
typedef pair<long long, long long> pii;
typedef long long ll;

int n, m, g, a[1002][1002], cyc[1002][1002], col[1002][1002];
char ch[1002][1002];
pii p[1002][1002];
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void vivod(int mas[1002][1002])
{
    for(int i  = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
            cout << mas[i][j] << " ";
        cout << "\n";
    }
    cout << "\n\n";
}
void vivod(char mas[1002][1002])
{
    for(int i  = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
            cout << mas[i][j] << " ";
        cout << "\n";
    }
    cout << "\n\n";
}
void vivod(pii mas[1002][1002])
{
    for(int i  = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
            cout << "|" << mas[i][j].xx << " " << mas[i][j].yy << "|    ";
        cout << "\n";
    }
    cout << "\n\n";
}


bool inpole(pii v)
{
    return v.xx >= 0 && v.xx < n && v.yy >= 0 && v.yy < m;
}

void dfs(pii st, pii v)
{
    p[v.xx][v.yy] = st;
    col[v.xx][v.yy] = 1;
    if((ch[v.xx][v.yy] == 's' || ch[v.xx][v.yy] == 'S') && col[v.xx+dx[0]][v.yy+dy[0]] == 0)
        dfs(st, {v.xx + dx[0], v.yy + dy[0]});
    if((ch[v.xx][v.yy] == 'e' || ch[v.xx][v.yy] == 'E') && col[v.xx+dx[1]][v.yy+dy[1]] == 0)
        dfs(st, {v.xx + dx[1], v.yy + dy[1]});
    if((ch[v.xx][v.yy] == 'n' || ch[v.xx][v.yy] == 'N') && col[v.xx+dx[2]][v.yy+dy[2]] == 0)
        dfs(st, {v.xx + dx[2], v.yy + dy[2]});
    if((ch[v.xx][v.yy] == 'w' || ch[v.xx][v.yy] == 'W') && col[v.xx+dx[3]][v.yy+dy[3]] == 0)
        dfs(st, {v.xx + dx[3], v.yy + dy[3]});
    for(int i = 0; i < 4; i++)
    {
        pii to = {v.xx + dx[i], v.yy + dy[i]};
        if(!inpole(to))
            continue;
        if(i == 0 && (ch[to.xx][to.yy] == 'N' || ch[to.xx][to.yy] == 'N') && col[to.xx][to.yy] == 0)
            dfs(st, to);
        if(i == 1 && (ch[to.xx][to.yy] == 'w' || ch[to.xx][to.yy] == 'W') && col[to.xx][to.yy] == 0)
            dfs(st, to);
        if(i == 2 && (ch[to.xx][to.yy] == 's' || ch[to.xx][to.yy] == 'S') && col[to.xx][to.yy] == 0)
            dfs(st, to);
        if(i == 3 && (ch[to.xx][to.yy] == 'e' || ch[to.xx][to.yy] == 'E') && col[to.xx][to.yy] == 0)
            dfs(st, to);
    }
    col[v.xx][v.yy] = 2;
}

bool search_cyc, cnt;
pii nc;
int len_cyc;

void dfsc(pii v)
{
    col[v.xx][v.yy] = 1;
    //cout << "   " << v.xx << " " << v.yy << " " << len_cyc << " " << nc.xx << "  " << nc.yy << "\n";
    //vivod(col);
    if((ch[v.xx][v.yy] == 's' || ch[v.xx][v.yy] == 'S'))
    {
        if(col[v.xx+dx[0]][v.yy+dy[0]] == 0)
            dfsc({v.xx + dx[0], v.yy + dy[0]});
        else
        {
            if(col[v.xx+dx[0]][v.yy+dy[0]] == 1)
            {
                search_cyc = true;
                cnt = true;
                len_cyc = 1;
                nc = {v.xx+dx[0], v.yy+dy[0]};
                col[v.xx][v.yy] = 2;
                return;
            }
        }
    }
    if((ch[v.xx][v.yy] == 'e' || ch[v.xx][v.yy] == 'E'))
    {
        if(col[v.xx+dx[1]][v.yy+dy[1]] == 0)
            dfsc({v.xx + dx[1], v.yy + dy[1]});
        else
        {
            if(col[v.xx+dx[1]][v.yy+dy[1]] == 1)
            {
                search_cyc = true;
                cnt = true;
                len_cyc = 1;
                nc = {v.xx+dx[1], v.yy+dy[1]};
                col[v.xx][v.yy] = 2;
                return;
            }
        }
    }
    if((ch[v.xx][v.yy] == 'n' || ch[v.xx][v.yy] == 'N'))
    {
        if(col[v.xx+dx[2]][v.yy+dy[2]] == 0)
            dfsc({v.xx + dx[2], v.yy + dy[2]});
        else
        {
            if(col[v.xx+dx[2]][v.yy+dy[2]] == 1)
            {
                search_cyc = true;
                cnt = true;
                len_cyc = 1;
                nc = {v.xx+dx[2], v.yy+dy[2]};
                //cout << nc.xx << " " << nc.yy  << "      " << v.xx << " " << v.yy << "  sdgsSas\n\n";
                col[v.xx][v.yy] = 2;
                return;
            }
        }
    }
    if((ch[v.xx][v.yy] == 'w' || ch[v.xx][v.yy] == 'W'))
    {
        if(col[v.xx+dx[3]][v.yy+dy[3]] == 0)
            dfsc({v.xx + dx[3], v.yy + dy[3]});
        else
        {
            if(col[v.xx+dx[3]][v.yy+dy[3]] == 1)
            {
                search_cyc = true;
                cnt = true;
                len_cyc = 1;
                nc = {v.xx+dx[3], v.yy+dy[3]};
               // cout << nc.xx << " " << nc.yy  << "      " << v.xx << " " << v.yy << "  AFD Sas\n\n";
                col[v.xx][v.yy] = 2;
                return;
            }
        }
    }
    col[v.xx][v.yy] = 2;
    if(search_cyc && cnt)
    {
        len_cyc++;
        if(v == nc)
            cnt = false;
    }
    //cout << ":  " << v.xx << " " << v.yy << " " << len_cyc << " " << nc.xx << "  " << nc.yy << "\n";
}



int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    //freopen("input.txt", "r", stdin);

    cin >> n >> m >> g;
    for(int i = 0; i < n; i++)
        for(int j  = 0; j < m; j++)
            cin >> ch[i][j];
    //vivod(ch);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            pii v = {i, j};
            if(col[i][j] == 0)
                dfs(v, v);
        }
    }
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            col[i][j] = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            pii v = p[i][j];
            if (col[v.xx][v.yy] == 0)
            {
                search_cyc = false;
                cnt = false;
                len_cyc = 0;
                dfsc(v);
                cyc[v.xx][v.yy] = len_cyc;
            }
        }
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            if(ch[i][j] == 'E' || ch[i][j] == 'W' || ch[i][j] == 'S' || ch[i][j] == 'N')
            {
                pii v = p[i][j];
                a[v.xx][v.yy]++;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
        {
            ans += min(a[i][j], cyc[i][j]);
        }
    cout << ans << "\n\n";
    //vivod(a);
    //vivod(cyc);
   // vivod(p);
    return 0;
}
