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

typedef long long ll;
typedef long double ld;
const ld INF = INFINITY;

#define s second
#define f first
#define pb push_back
#define m0(x) memset(x,0,sizeof(x))

#define TASK "robots"

ll n,m,g;
char ch[1005][1005];
int vis[1005][1005];
int pc[1005][1005];
map<ll,ll> mp,color;

bool robot(char ch){
    return (ch=='N' || ch=='E' || ch=='W' || ch=='S');
}

int f(char ch){
    if(ch=='n' || ch=='N') return 1;
    if(ch=='s' || ch=='S') return 2;
    if(ch=='w' || ch=='W') return 3;
    if(ch=='e' || ch=='E') return 4;
}

void bfs(int i, int j,ll &len,ll &rob,ll &clr){
    ll h = 0,k = 0,x = 1;
    while(!vis[i][j]){
        pc[i][j] = x;
        h++;
        vis[i][j] = clr;
        if(robot(ch[i][j])) k++;
        int q = f(ch[i][j]);
        if(q==1) i--; if(q==2) i++; if(q==3) j--; if(q==4) j++;
        ++x;
    }
    if(vis[i][j]!=clr) {

        ll nclr = clr;
        clr = color[vis[i][j]];
        color[nclr] = clr;
        //cross = vis[i][j];
        rob = k;
        len = mp[clr];
        return;
    }
    len = h - pc[i][j] + 1;
    //cout<<"circle "<<clr<<" "<<len<<" "<<k<<endl;
    rob = k;
    color[clr] = clr;
    return;
}


int solve(){
    cin>>n>>m>>g;

    m0(vis);

    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            cin>>ch[i][j];
        }

    ll len = 0,rob = 0,clr = 0,res = 0,cross;
    bool z;

    ll glclr = 0;


    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++){
            if(!vis[i][j]){
                len = 0;
                rob = 0;
                glclr++;
                clr = glclr;
                bfs(i,j,len,rob,clr);
                res+=min(len,rob);
                mp[clr] = max((ll)0,len - rob);
      //          cout<<"ans "<<i<<" "<<j<<" "<<res<<endl;
            }
        }
    cout<<res;
    return 0;
}

int main(){
    freopen(TASK".in","r",stdin);
    freopen(TASK".out","w",stdout);

    solve();

    /*cout<<endl;
    for(int i=0;i<n;i++,cout<<endl)
        for(int j=0;j<n;j++){
            cout<<vis[i][j]<<" ";
        }
    cout<<endl;
    for(auto i : color)
        cout<<i.f<<" "<<i.s<<endl;*/

    return 0;
}
