#include <bits/stdc++.h>

using namespace std;

int mas[1001][1001], can[1001][1001];
string s[1001];
int used[1001][1001];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int t;
vector<pair<int, int> > a;
vector<pair<int, int> > arr[1001][1001];

void dfs(int x, int y)
{
    used[x][y] = 1;
    int q = x + dx[mas[x][y]];
    int w = y + dy[mas[x][y]];
    if (used[q][w] == 0)
        dfs(q, w);
    else if (used[q][w] == 1)
        a.push_back({q, w});
    arr[q][w].push_back({x, y});
    used[x][y] = 2;
}

int dfs2(int x, int y)
{
    int col = can[x][y];
    used[x][y] = 3;
    for (int i = 0; i < arr[x][y].size(); i++)
    {
        int q = arr[x][y][i].first;
        int w = arr[x][y][i].second;
        if (used[q][w] == 2)
        {
            col += dfs2(q, w);
        }
    }
    return col;
}

int main()
{
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    cin.tie(0);
    int n, m, g;
    cin >> n >> m >> g;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        for (int j = 0; j < m; j++)
        {
            used[i][j] = 0;
            if (s[i][j] == 'S' || s[i][j] == 'N' || s[i][j] == 'E' || s[i][j] == 'W')
                can[i][j] = 1;
            else
                can[i][j] = 0;
            if (s[i][j] == 'S' || s[i][j] == 's')
                mas[i][j] = 0;
            else if (s[i][j] == 'N' || s[i][j] == 'n')
                mas[i][j] = 1;
            else if (s[i][j] == 'W' || s[i][j] == 'w')
                mas[i][j] = 2;
            else
                mas[i][j] = 3;
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (used[i][j] == 0)
            {
                dfs(i, j);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < a.size(); i++)
    {
        int x = a[i].first;
        int y = a[i].second;
        int num = 1;
        int t = mas[x][y];
        x += dx[t];
        y += dy[t];
        while (x != a[i].first || y != a[i].second)
        {
            num++;
            t = mas[x][y];
            x += dx[t];
            y += dy[t];
        }
        int col = dfs2(x, y);
        ans += min(num, col);
        //cout << x << " " << y << " " << num << " " << col << endl;
    }
    cout << ans << endl;
    return 0;
}

