#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <set>

using namespace std;

int n, m;

char color[1000][1000];
int arr[1000][1000];

vector<pair<int, int> > cycl;

int check(int x, int y)
{
    if(x < 0 || y < 0) return 0;
    if(x >= m || y >= n) return 0;
    return 1;
}

int offsetX[4] = {0, 1, 0, -1};
int offsetY[4] = {-1, 0, 1, 0};

void dfs(int x, int y)
{
    if(color[x][y] == 'B') return;
    if(color[x][y] == 'G')
    {
        cycl.push_back(make_pair(x, y));
        return;
    }

    color[x][y] = 'G';

    dfs(x + offsetX[arr[x][y]-1], y + offsetY[arr[x][y]-1]);

    color[x][y] = 'B';
}

int f;
int calc(int x, int y, int x1, int y1)
{
    if(f == 1 && x == x1 && y == y1) return 0;
    if(f == 0) f = 1;

    return calc(x + offsetX[arr[x][y]-1], y + offsetY[arr[x][y]-1], x1, y1) + 1;
}



int main()
{
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);

    int g;
    cin >> n >> m >> g;

    for(int y = 0; y < n; y++)
    {
        for(int x = 0; x < m; x++)
        {
            char c;
            cin >> c;
            if(c == 'N') arr[x][y] = 1;
            if(c == 'E') arr[x][y] = 2;
            if(c == 'S') arr[x][y] = 3;
            if(c == 'W') arr[x][y] = 4;
        }
    }

    for(int y = 0; y < n; y++)
    {
        for(int x = 0; x < m; x++)
        {
            color[x][y] = 'W';
        }
    }

    for(int y = 0; y < n; y++)
    {
        for(int x = 0; x < m; x++)
        {
            if(color[x][y] == 'W') dfs(x, y);
        }
    }


    int ans = 0;

    for(int i = 0; i < cycl.size(); i++)
    {
        f = 0;
        ans += calc(cycl[i].first, cycl[i].second, cycl[i].first, cycl[i].second);
    }

    cout << ans << endl;




    return 0;
}
