#include <fstream>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

vector<int> v(10000, 0);
vector<int> visited(10000, 0);

int dfs(int i){
    visited[i] = 1;
    if(visited[v[i]] == 0){
        dfs(v[i]);
    }
    else{
        visited[v[i]] = 2;
        return 0;
    }
}

int main(){
    ifstream in("robots.in");
    ofstream out("robots.out");
    int n, m, g;
    in >> n >> m >> g;
    vector<int> robots(0);
    unsigned char a;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            in >> a;
            if (a == 78 or a == 83 or a == 69 or a == 87){
                robots.push_back(i * n + j);
            }
            if(a == 78 or a == 110) v[i * m + j] = (i - 1) * m + j;
            if(a == 83 or a == 115) v[i * m + j] = (i + 1) * m + j;
            if(a == 69 or a == 101) v[i * m + j] = (i) * m + j + 1;
            if(a == 87 or a == 119) v[i * m + j] = (i) * m + j - 1;
        }
    }
    if(robots.size() == n * m){
        long long res = 0;
        for(int i = 0; i < n * m; i++){
            for(int j = 0; j < n * m; j++){
                visited[j] = 0;
            }
            dfs(i);
            if(visited[i] == 2){
                res += 1;
            }
        }
        out << res;
    }
    return 0;
}
