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

using namespace std;

void dfs(int i, int j, vector< vector< pair<int, int> > >& mmap, vector< vector <int> >& mas, int color){
    mas[i][j] = color;

    if (mas[i + mmap[i][j].first][j + mmap[i][j].second] != color){
        dfs(i + mmap[i][j].first, j + mmap[i][j].second, mmap, mas, color);
    }

    int ci, cj;
    ci = i + 1;
    cj = j;

    if (0 <= ci && ci < mas.size() && mas[ci][cj] != color && mas[ci + mmap[ci][cj].first][cj + mmap[ci][cj].second] == color){
        dfs(ci, cj, mmap, mas, color);
    }

    ci = i - 1;
    cj = j;

    if (0 <= ci && ci < mas.size() && mas[ci][cj] != color && mas[ci + mmap[ci][cj].first][cj + mmap[ci][cj].second] == color){
        dfs(ci, cj, mmap, mas, color);
    }

    ci = i;
    cj = j + 1;

    if (0 <= cj && cj < mas[0].size() && mas[ci][cj] != color && mas[ci + mmap[ci][cj].first][cj + mmap[ci][cj].second] == color){
        dfs(ci, cj, mmap, mas, color);
    }

    ci = i;
    cj = j - 1;

    if (0 <= cj && cj < mas[0].size() && mas[ci][cj] != color && mas[ci + mmap[ci][cj].first][cj + mmap[ci][cj].second] == color){
        dfs(ci, cj, mmap, mas, color);
    }
}

void search_cycle(int i, int j, vector< vector< pair<int, int> > >& mmap, vector< pair<int, int> >& path, vector< vector<bool> >& used, pair<int, int>& beg){
    used[i][j] = true;
    path.push_back(make_pair(i, j));
    if (used[i + mmap[i][j].first][j + mmap[i][j].second] == true){
        beg = make_pair(i + mmap[i][j].first, j + mmap[i][j].second);
    }
    else{
        search_cycle(i + mmap[i][j].first, j + mmap[i][j].second, mmap, path, used, beg);
    }
}

int main(){
    ifstream fin("robots.in");
    ofstream fout("robots.out");


    int n, m, g;

    fin >> n >> m >> g;

    vector< vector<int> > mas(n, vector<int>(m, -1));
    vector< vector< pair<int, int> > > mmap(n, vector< pair<int, int> >(m));
    vector< pair<int, int> > robots;
    char cur;


    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            cin >> cur;
            if (cur == 'S'){
                robots.push_back(make_pair(i, j));
                mmap[i][j] = make_pair(1, 0);
            }
            else if (cur == 'N'){
                robots.push_back(make_pair(i, j));
                mmap[i][j] = make_pair(-1, 0);
            }
            else if (cur == 'W'){
                robots.push_back(make_pair(i, j));
                mmap[i][j] = make_pair(0, -1);
            }
            else if (cur == 'E'){
                robots.push_back(make_pair(i, j));
                mmap[i][j] = make_pair(0, 1);
            }
            else if (cur == 's'){
                mmap[i][j] = make_pair(1, 0);
            }
            else if (cur == 'n'){
                mmap[i][j] = make_pair(-1, 0);
            }
            else if (cur == 'w'){
                mmap[i][j] = make_pair(0, -1);
            }
            else if (cur == 'e'){
                mmap[i][j] = make_pair(0, 1);
            }
        }
    }

    int color = 1;
    for(int i = 0; i < robots.size(); ++i){
        if (mas[robots[i].first][robots[i].second] == -1){
            dfs(robots[i].first, robots[i].second, mmap, mas, color);
            color++;
        }
    }

    vector<int> for_ans(color, -1);
    int ans = 0;

    for(int i = 0; i < robots.size(); ++i){
        if (for_ans[mas[robots[i].first][robots[i].second]] == -1){
            vector< pair<int, int> > path;
            vector< vector<bool> > used(n, vector<bool>(m, false));
            pair<int, int> beg;

            search_cycle(robots[i].first, robots[i].second, mmap, path, used, beg);

            for(int j = 0; j < path.size(); ++j){
                if (path[j] == beg){
                    for_ans[mas[robots[i].first][robots[i].second]] = path.size() - j;
                }
            }
        }

        if (for_ans[mas[robots[i].first][robots[i].second]] > 0){
            ans++;
            for_ans[mas[robots[i].first][robots[i].second]] -= 1;
        }
    }

    fout << ans << endl;

    fin.close();
    fout.close();
    return 0;
}
