#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    map<char, int> dx;
    map<char, int> dy;
    dx['S'] = 0;
    dx['s'] = 0;
    dx['N'] = 0;
    dx['n'] = 0;
    dx['E'] = 1;
    dx['e'] = 1;
    dx['W'] = -1;
    dx['w'] = -1;
    dy['S'] = 1;
    dy['s'] = 1;
    dy['N'] = -1;
    dy['n'] = -1;
    dy['E'] = 0;
    dy['e'] = 0;
    dy['W'] = 0;
    dy['w'] = 0;
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    int n, m, g;
    cin >> n >> m >> g;
    map<int, int> size;
    map<int, int> res;
    vector<vector<char>> our(n, vector<char>(m));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
            cin >> our[i][j];
    }
    vector<vector<int>> my(n, vector<int>(m));
    vector<vector<int>> time(n, vector<int>(m));
    int t = 1, ti = 1;
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            int x = i, y = j, found = 0;
            while (my[y][x] == 0)
            {
                if (our[y][x] < 'Z')
                    found++;
                my[y][x] = t;
                time[y][x] = ti;
                ti++;
                int ox = x;
                x += dx[our[y][x]];
                y += dy[our[y][ox]];
            }
            if (my[y][x] == t)
            {
                size[t] = ti - time[y][x];
                res[t] = min(found, size[t]);
            }
            else
            {
                res[my[y][x]] = min(size[my[y][x]], found + res[my[y][x]]);
                int color = my[y][x];
                x = i;
                y = j;
                while (my[y][x] != color)
                {
                    my[y][x] = color;
                    int ox = x;
                    x += dx[our[y][x]];
                    y += dy[our[y][ox]];
                }
            }
            t++;
        }
    }
    int ans = 0;
    for (auto e: res)
        ans += e.second;
    cout << ans;
}
/*
3 4 0
SSSS
EESW
ENWW

3 4 0
SSSS
EeSW
ENwW

4 4 0
essS
Eess
Snww
EeWN
 */