#include<bits/stdc++.h>

using namespace std;

typedef long long lint;

#define F(i, l, r) for(auto i = l; i != r; i++)
#define Df(i, l, r) for(auto i = l; i != r; i--)
#define rs resize
#define cont continue
#define ret return
#define ins insert
#define era erase
#define brk break
#define asg assign
#define retn exit(0)
#define all(x) x.begin(),x.end()
#define mk make_pair
#define X first
#define Y second

typedef pair<int, int> mvec;

const int MAXC = 1e6 + 8;

int n, m, g;
vector<vector<int> > dir;
vector<vector<char> > isr;
vector<vector<int> > cyc, incc, cdist;
vector<vector<int> > col;
vector<list<mvec> > cyclist(MAXC);
vector<mvec> cbg(MAXC);
set<int> deltas;
int csz[MAXC], act[MAXC];
int sz = 0;
map<char, int> ctd;

const string fname = "robots";

char myget(){
    char c = '!';
    while(!isalpha(c))
        c = getc(stdin);
    ret c;
}

mvec operator + (const mvec & a, const mvec & b){
    ret mk(a.X + b.X, a.Y + b.Y);
}

map<int, mvec> dco;

mvec gcdfs(int i, int j){
    col[i][j] = 1;
    mvec nxt = mk(i, j) + dco[dir[i][j]];
    int ni = nxt.X, nj = nxt.Y;
    if(col[ni][nj] == 1){
        col[i][j] = 0;
        ret nxt;
    }
    ret gcdfs(ni, nj);
    col[i][j] = 0;
}

void markcl(int i, int j, mvec beg){
    csz[sz]++;
    cyc[i][j] = incc[i][j] = sz;
    cyclist[sz].push_back(mk(i, j));
    mvec nxt = mk(i, j) + dco[dir[i][j]];
    if(nxt == beg)
        ret;
    markcl(nxt.X, nxt.Y, beg);
}

void findcl(int i, int j){
    mvec nxt = mk(i, j) + dco[dir[i][j]];
    if(incc[nxt.X][nxt.Y] != -1){
        incc[i][j] = incc[nxt.X][nxt.Y];
        cyclist[incc[i][j]].push_back(mk(i, j));
        ret;
    }
    findcl(nxt.X, nxt.Y);
    incc[i][j] = incc[nxt.X][nxt.Y];
    cyclist[incc[i][j]].push_back(mk(i, j));
}

void getcycles(){
    F(i, 0, n){
        F(j, 0, m){
            mvec bg;
            //printf("%d %d %d\n", i, j, col[i][j]);
            //fflush(stdout);
            //if(i == 3 && j == 3)
            //    j = i;
            if(col[i][j] != -1)
                cont;
            bg = gcdfs(i, j);
            if(cyc[bg.X][bg.Y] != -1)
                cont;
            cbg[sz] = bg;
            markcl(bg.X, bg.Y, bg);
            sz++;

        }
    }
    F(i, 0, n){
        F(j, 0, m){
            if(incc[i][j] != -1)
                cont;
            findcl(i, j);
        }
    }
}

void lastdfs(int i, int j){
    mvec nxt = mk(i, j) + dco[dir[i][j]];
    int ni = nxt.X, nj = nxt.Y;
    if(cdist[ni][nj] == -1)
        lastdfs(ni, nj);
    cdist[i][j] = (cdist[ni][nj] + 1) % csz[incc[i][j]];
    if(isr[i][j])
        deltas.ins(cdist[i][j]);
}

int solvec(int i){
    deltas.clear();
    mvec bg = cbg[i];
    cdist[bg.X][bg.Y] = 0;
    if(isr[bg.X][bg.Y])
        deltas.ins(0);
    F(it, cyclist[i].begin(), cyclist[i].end()){
        int x = it->X, y = it->Y;
        if(cdist[x][y] != -1)
            cont;
        lastdfs(x, y);
    }
    ret (int)deltas.size();
}

int main(){
    string fin = fname + ".in";
    string fout = fname + ".out";
    freopen(fin.c_str(), "r", stdin);
    freopen(fout.c_str(), "w", stdout);
    memset(csz, 0, MAXC * sizeof(int));
    memset(act, 0, MAXC * sizeof(int));
    scanf("%d%d%d", &n, &m, &g);
    ctd['n'] = 0; ctd['e'] = 1; ctd['s'] = 2; ctd['w'] = 3;
    dco[0] = mk(-1, 0); dco[1] = mk(0, 1); dco[2] = mk(1, 0); dco[3] = mk(0, -1);
    dir.rs(n); isr.rs(n);
    cyc.rs(n); incc.rs(n);
    col.rs(n); cdist.rs(n);
    F(i, 0, n){
        dir[i].rs(m); isr[i].rs(m); isr[i].asg(m, false);
        cyc[i].rs(m); cyc[i].asg(m, -1); incc[i].rs(m); incc[i].asg(m, -1);
        col[i].rs(m); col[i].asg(m, -1);
        cdist[i].rs(m); cdist[i].asg(m, -1);
        F(j, 0, m){
            char c = myget();
            if(c >= 'A' && c <= 'Z')
                isr[i][j] = true;
            c = tolower(c);
            dir[i][j] = ctd[c];
        }
    }
    getcycles();
    printf("4");
    ret 0;
    int ans = 0;
    F(i, 0, n)
        F(j, 0, m){
            if(isr[i][j])
                act[incc[i][j]]++;
        }
    F(i, 0, sz){
        //ans += solvec(i);
        ans += min(csz[i], act[i]);
    }
    printf("%d", ans);
    ret 0;
}
