#include <bits/stdc++.h>

#define vec vector
#define forn(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
#define YY second
#define XX first
#define vec vector
#define str string
#define pb push_back
#define ll long long
#define all(a) a.begin(), a.end()

using namespace std;

const bool is_testing = false;

int n, m, g;
char a[1007][1007];
bool was[1007][1007];
bool is[1007][1007];

void dfs(int x, int y, vec< pair<int, int> > pred)
{
    if (was[x][y])
    {
        bool f = false;
        forn(i, pred.size())
            if (pred[i] == mp(x, y))
                f = true;
        if (f)
        {
            pair<int, int> start = mp(x, y);
            is[x][y] = true;
            reverse(all(pred));
            forn(i, pred.size())
                if (pred[i] != start)
                {
                    is[pred[i].XX][pred[i].YY] = true;
                }
                else
                    break;
        }
    }
    else
    {
        was[x][y] = true;
        pred.pb(mp(x, y));
        if (a[x][y] == 'S')
            dfs(x + 1, y, pred);
        if (a[x][y] == 'N')
            dfs(x - 1, y, pred);
        if (a[x][y] == 'W')
            dfs(x, y - 1, pred);
        if (a[x][y] == 'E')
            dfs(x, y + 1, pred);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie();
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    if (is_testing)
    {
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    }
    cin >> n >> m >> g;
    forn(i, n)
        forn(j, m)
            cin >> a[i][j];
    forn(i, n)
        forn(j, m)
        if (!was[i][j])
        {
            vec < pair<int, int> > q;
            dfs(i, j, q);
        }
    int ans = 0;
    forn(i, n)
        forn(j, m)
            if (is[i][j])
                ans++;
    //forn(i, n)
    //{
    //    forn(j, m)
    //        cout << is[i][j];
    //    cout << endl;
    //}
    cout << ans;
}
