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

using namespace std;

vector<long long> v(1000000, 0);
vector<bool> visited(1000000, 0);
vector<bool> visited1(1000000, 0);

long long dfs1(long long i, long long j){
    visited[i] = true;
    if(visited1[i] == false){
        visited1[j] = false;
        j = i;
        visited1[j] = true;
    }
    if(visited[v[i]] == false){
        dfs1(v[i], j);
    }
    else{
        return j;
    }
}

int dfs(long long i, long long j){
    visited[i] = true;
    if(visited[v[i]] == false){
        return(dfs(v[i], j));
    }
    else{
        if(v[i] == j) return 1;
        else return 0;
    }
}

int main(){
    ifstream in("robots.in");
    ofstream out("robots.out");
    int n, m, g;
    in >> n >> m >> g;
    vector<long long> 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 * m + 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;
    }*/
    //else{
    long long res = 0;
    vector<long long> robots1(0);
        for(long long i = 0; i < robots.size(); i++){
            visited1[robots[i]] = true;
        }
        for(long long i = 0; i < robots.size(); i++){
            for(long long j = 0; j < n * m; j++){
                visited[j] = false;
            }
            robots1.push_back(dfs1(robots[i], robots[i]));
        }
        for(long long i = 0; i < robots1.size(); i++){
            for(long long j = 0; j < n * m; j++){
                visited[j] = false;
            }
            res += dfs(robots1[i], robots1[i]);
        }
        out << res;
    //}
    return 0;
}
