#include <bits/stdc++.h>

using namespace std;

string s[1000];
int u[1000][1000];
pair<int, int> prevv[1000][1000];
bool b[1000][1000];
int cyc[1000][1000];
int pa[1000][1000];
int cnt[1000000];

map<char, pair<int, int> > turn;
int num = 0;

pair<int, int> fi;
pair<int, int> now;
int nowcyc;

void dfs(int i, int j, int pi, int pj){
    u[i][j] = 1;
    //cyc[i][j] = num;
    if (u[i + turn[s[i][j]].first][j + turn[s[i][j]].second] == 0){
        dfs(i + turn[s[i][j]].first, j + turn[s[i][j]].second, i, j);
        prevv[i + turn[s[i][j]].first][j + turn[s[i][j]].second] = {i, j};
    }
    else{
        if (u[i + turn[s[i][j]].first][j + turn[s[i][j]].second] == 1){
            fi = {i + turn[s[i][j]].first, j + turn[s[i][j]].second};
            now = {i, j};
            nowcyc = num;
        }
        else{
            now = {i, j};
            nowcyc = cyc[i + turn[s[i][j]].first][j + turn[s[i][j]].second];
        }
    }
}

int main()
{
    ifstream cin("robots.in");
    ofstream cout("robots.out");
    int n, m, type;
    cin >> n >> m >> type;
    for (int i = 0; i < n; i++)
        cin >> s[i];

    turn['N'] = {-1, 0};
    turn['n'] = {-1, 0};
    turn['S'] = {1, 0};
    turn['s'] = {1, 0};
    turn['w'] = {0, -1};
    turn['W'] = {0, -1};
    turn['E'] = {0, 1};
    turn['e'] = {0, 1};

    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++)
            if (s[i][j] >= 'A' && s[i][j] <= 'Z')
                b[i][j] = 1;
    }

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        if (!u[i][j]){
            fi = {-1, -1};
            prevv[i][j] = {-1, -1};
            dfs(i, j, -1, -1);

            bool fl = 0;
            while (now != fi){
                if (fi == make_pair(-1, -1))
                    break;
                u[now.first][now.second] = 2;
                cyc[now.first][now.second] = num;
                cnt[num]++;
                //v.push_back(now);
                now = {prevv[now.first][now.second]};
                fl = 1;
            }
            if (fi != make_pair(-1, -1)){
                u[now.first][now.second] = 2;
                cyc[now.first][now.second] = nowcyc;
                cnt[nowcyc]++;
            }
            //v.push_back(now);
            //reverse(v.begin(), v.end());
            while (prevv[now.first][now.second] != make_pair(-1, -1)){
                //pa[now.first][now.second] = num;
                cyc[now.first][now.second] = nowcyc;
                u[now.first][now.second] = 2;
                now = {prevv[now.first][now.second]};
            }
            //pa[now.first][now.second] = num;
            cyc[now.first][now.second] = nowcyc;
            num += fl;
        }
    int ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (b[i][j] && cnt[cyc[i][j]] > 0){
                cnt[cyc[i][j]]--;
                ans++;
            }
        }
    }

    cout << ans;
    return 0;
}
