#include <iostream>
#include <fstream>
#include <vector>
#include <map>

using namespace std;

char pole[1010][1010];
int clr[1010][1010];
int cycle[1010][1010];
int nachx;
vector<int> pr;
int adept[500100];
int nachy;
int lengthcycle=0;
int now=1;
void dfs(int x,int y,int p)
{
    if (cycle[x][y]>0){return;}
    if (clr[x][y]!=p)
    {
        clr[x][y]=p;
        if (pole[x][y]=='E'||pole[x][y]=='e'){dfs(x+1,y,p);cycle[x][y]=cycle[x+1][y];}
        if (pole[x][y]=='S'||pole[x][y]=='s'){dfs(x,y+1,p);cycle[x][y]=cycle[x][y+1];}
        if (pole[x][y]=='W'||pole[x][y]=='w'){dfs(x-1,y,p);cycle[x][y]=cycle[x-1][y];}
        if (pole[x][y]=='N'||pole[x][y]=='n'){dfs(x,y-1,p);cycle[x][y]=cycle[x][y-1];}
        if (pole[x][y]<'e'){adept[cycle[x][y]]++;}
        lengthcycle++;
        if (x==nachx&&y==nachy){pr.push_back(lengthcycle);}
    }
    else
    {
        cycle[x][y]=now;
        nachx=x;
        nachy=y;
        now++;
    }
}


int main()
{
    pr.push_back(-1);
    freopen("robots.in","r",stdin);
    freopen("robots.out","w",stdout);
    int n,m,g;
    cin >> n >> m >> g;
    int kol=0;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            cin >> pole[j][i];
            //if (pole[i][j]=="")
        }
    }
    int y=1;
    for (int i=1;i<=n;i++)
    {
         for (int j=1;j<=m;j++)
         {
             lengthcycle=0;
             nachx=nachy=-1;
             if (pole[j][i]<'e'&&clr[j][i]==0)
             {dfs(j,i,y);
             y++;}
         }
    }
    int res=0;
    for (int i=1;i<pr.size();i++)
    {
        //cout << pr[i] << ' ' << adept[i] << endl;
        res+=min(pr[i],adept[i]);

    }
    cout << res;

    return 0;
}
