#include <bits/stdc++.h>
#define pii pair<int,int>
#define ff first
#define ss second
#define puba push_back
using namespace std;
const int N=1000;
char a[N][N];
int b[N][N];
vector<pii> cycles;

void dfs1(int i, int j)
{
    int ii=i,jj=j;
    if(a[i][j]=='N'||a[i][j]=='n')
        ii--;
    else if(a[i][j]=='S'||a[i][j]=='s')
        ii++;
    else if(a[i][j]=='W'||a[i][j]=='w')
        jj--;
    else
        jj++;

    if(b[ii][jj]==-1)
    {
        b[ii][jj]=b[i][j];
        dfs1(ii,jj);
    }
    else if(b[ii][jj]==b[i][j])
        cycles.puba({ii,jj});
}

map<pii,pii> cnt;
pii c[N][N];

void dfs2(int i, int j, pii cval)
{
    c[i][j]=cval;
    int ii=i,jj=j;
    if(a[i][j]=='N'||a[i][j]=='n')
        ii--;
    else if(a[i][j]=='S'||a[i][j]=='s')
        ii++;
    else if(a[i][j]=='W'||a[i][j]=='w')
        jj--;
    else
        jj++;
    if(a[i][j]=='N'||a[i][j]=='S'||a[i][j]=='W'||a[i][j]=='E')
        cnt[cval].ff++;
    if(c[ii][jj].ff==-1)
        dfs2(ii,jj,cval),cnt[cval].ss++;
}

void dfs3(int i, int j)
{
    int ii=i,jj=j;
    if(a[i][j]=='N'||a[i][j]=='n')
        ii--;
    else if(a[i][j]=='S'||a[i][j]=='s')
        ii++;
    else if(a[i][j]=='W'||a[i][j]=='w')
        jj--;
    else
        jj++;
    if(c[ii][jj].ff!=-1)
        cnt[c[ii][jj]].ff++;
    else
        dfs3(ii,jj);
}

int main()
{
    ios_base::sync_with_stdio(0);
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    ifstream cin("robots.in");
    ofstream cout("robots.out");

    int n,m,g;
    cin>>n>>m>>g;
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            cin>>a[i][j],b[i][j]=-1,c[i][j]={-1,-1};

    int cur=0;
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            if(b[i][j]==-1&&(a[i][j]=='N'||a[i][j]=='S'||a[i][j]=='W'||a[i][j]=='E'))
                b[i][j]=cur++,dfs1(i,j);

    int res=0;
    for(int i=0,sz=(int)cycles.size(); i<sz; i++)
    {
        cnt[cycles[i]].ss=1;
        dfs2(cycles[i].ff,cycles[i].ss,cycles[i]);
    }

    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            if(c[i][j].ff==-1&&(a[i][j]=='N'||a[i][j]=='S'||a[i][j]=='W'||a[i][j]=='E'))
                dfs3(i,j);

    for(map<pii,pii>::iterator it=cnt.begin(); it!=cnt.end(); it++)
        res+=min((*it).ss.ff,(*it).ss.ss);

    cout<<res;
    return 0;
}
