#include <bits/stdc++.h>
using namespace std;


const int MAX_N = 1001;
const int MAX_M = 1001;
map<char, int> dir_x, dir_y;
string a[MAX_N];
int b[MAX_N][MAX_M], t[MAX_N][MAX_M];
bool used[MAX_N][MAX_M];
int count_in_cycles[MAX_N * MAX_M], count_of_robots[MAX_N * MAX_M];
int c = 1;


int dfs1(int i, int j, int k)
{
    int new_i = i + dir_y[a[i][j]];
    int new_j = j + dir_x[a[i][j]];
    b[i][j] = k;
    if (b[new_i][new_j] != 0)
    {
        k = b[new_i][new_j];
    }
    else
    {
        k = dfs1(new_i, new_j, k);
    }
    b[i][j] = k;
    return k;
}


int dfs2(int i, int j, int k)
{
    t[i][j] = k;
    used[i][j] = true;
    int new_i = i + dir_y[a[i][j]];
    int new_j = j + dir_x[a[i][j]];
    if (used[new_i][new_j])
    {
        return k - t[new_i][new_j] + 1;
    }
    else
    {
        return dfs2(new_i, new_j, k + 1);
    }
}


int main()
{
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    int n, m, g;
    cin >> n >> m >> g;
    dir_x['e'] = 1;
    dir_y['e'] = 0;
    dir_x['E'] = 1;
    dir_y['E'] = 0;
    dir_x['w'] = -1;
    dir_y['w'] = 0;
    dir_x['W'] = -1;
    dir_y['W'] = 0;
    dir_x['s'] = 0;
    dir_y['s'] = 1;
    dir_x['S'] = 0;
    dir_y['S'] = 1;
    dir_x['n'] = 0;
    dir_y['n'] = -1;
    dir_x['N'] = 0;
    dir_y['N'] = -1;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            if (b[i][j] == 0)
            {
                dfs1(i, j, c);
                c++;
            }
        }
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            if ((a[i][j] == 'E') || (a[i][j] == 'W') || (a[i][j] == 'S') || (a[i][j] == 'N'))
            {
                ++count_of_robots[b[i][j]];
            }
        }
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            if (count_in_cycles[b[i][j]] == 0)
            {
                count_in_cycles[b[i][j]] = dfs2(i, j, 1);
            }
        }
    }
    int ans = 0;
    for (int i = 1; i < c; ++i)
    {
        ans += min(count_in_cycles[i], count_of_robots[i]);
    }
    cout << ans << endl;
    return 0;
}
