#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector<char> field[1009];
vector<int> loop[1009];
vector<int> depth[1009];
vector<int> loopsize;
vector<int> loopbots;

int main()
{
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    int h, w, g;
    cin >> h >> w >> g;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            char a;
            cin >> a;
            field[i].push_back(a);
            loop[i].push_back(-1);
            depth[i].push_back(1000009);
        }
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            int botcount = 0;
            int depthnow = 0;
            int x = i;
            int y = j;
            while (depth[x][y] > depthnow && loop[x][y] == -1)
            {
                depthnow++;
                switch(field[x][y])
                {
                case 'N':
                    botcount++;
                    depth[x][y] = depthnow;
                    x--;
                    break;
                case 'S':
                    botcount++;
                    depth[x][y] = depthnow;
                    x++;
                    break;
                case 'W':
                    botcount++;
                    depth[x][y] = depthnow;
                    y--;
                    break;
                case 'E':
                    botcount++;
                    depth[x][y] = depthnow;
                    y++;
                    break;
                case 'n':
                    depth[x][y] = depthnow;
                    x--;
                    break;
                case 's':
                    depth[x][y] = depthnow;
                    x++;
                    break;
                case 'w':
                    depth[x][y] = depthnow;
                    y--;
                    break;
                case 'e':
                    depth[x][y] = depthnow;
                    y++;
                    break;
                }
            }
            int paintloop = 0;
            if (loop[x][y] == -1)
            {
                paintloop = loopsize.size();
                loopsize.push_back(depthnow - depth[x][y] + 1);
                loopbots.push_back(botcount);
            }
            else
            {
                paintloop = loop[x][y];
                loopbots[loop[x][y]] += botcount;
            }
            x = i;
            y = j;
            while (loop[x][y] == -1)
            {
                loop[x][y] = paintloop;
                depth[x][y] = 1000009;
                switch(field[x][y])
                {
                case 'N':
                    x--;
                    break;
                case 'S':
                    x++;
                    break;
                case 'W':
                    y--;
                    break;
                case 'E':
                    y++;
                    break;
                case 'n':
                    x--;
                    break;
                case 's':
                    x++;
                    break;
                case 'w':
                    y--;
                    break;
                case 'e':
                    y++;
                    break;
                }
            }
        }
    }
    /*for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cerr << loop[i][j] << " ";
        }
        cerr << endl;
    }*/
    int total = 0;
    for (int i = 0; i < loopsize.size(); i++)
    {
        /*cerr << loopsize[i] << " " << loopbots[i] << endl;*/
        total += min(loopsize[i], loopbots[i]);
    }
    cout << total << endl;
    return 0;
}
