#include <iostream>
#include <bits/stdc++.h>

using namespace std;
vector<vector<char> > arr;
vector<vector<long long> > used;
vector<vector<long long> > t;
vector<vector<long long> > s;
vector<vector<long long> > q;
vector<long long> w;
vector<long long> u;

long long dfs(long long x, long long y, long long c, long long e, long long b)
{
    used[x][y] = c;
    t[x][y] = e;
    s[x][y] = b;
    if (arr[x][y] == 'E' || arr[x][y] == 'e')
    {
        if (used[x][y + 1] == 0)
        {
            long long ans = dfs(x, y + 1, c, e + 1, b + ((arr[x][y + 1] < 'a') ? 1 : 0));
            q[x][y] = q[x][y + 1];
            return ans;
        }
        else if (used[x][y + 1] == c)
        {
            w.push_back(e - t[x][y + 1] + 1);
            q[x][y + 1] = w.size();
            q[x][y] = w.size();
            u.push_back(s[x][y]);
            return w[w.size() - 1];
        }
        else
        {
            u[q[x][y]] += s[x][y];
            q[x][y] = q[x][y + 1];
            return 0;
        }
    }
    if (arr[x][y] == 'W' || arr[x][y] == 'w')
    {
        if (used[x][y - 1] == 0)
        {
            long long ans = dfs(x, y - 1, c, e + 1, b + ((arr[x][y - 1] < 'a') ? 1 : 0));
            q[x][y] = q[x][y - 1];
            return ans;
        }
        else if (used[x][y - 1] == c)
        {
            w.push_back(e - t[x][y - 1] + 1);
            q[x][y - 1] = w.size();
            q[x][y] = w.size();
            u.push_back(s[x][y]);
            return w[w.size() - 1];
        }
        else
        {
            u[q[x][y]] += s[x][y];
            q[x][y] = q[x][y - 1];
            return 0;
        }
    }
    if (arr[x][y] == 'N' || arr[x][y] == 'n')
    {
        if (used[x - 1][y] == 0)
        {
            long long ans = dfs(x - 1, y, c, e + 1, b + ((arr[x - 1][y] < 'a') ? 1 : 0));
            q[x][y] = q[x - 1][y];
            return ans;
        }
        else if (used[x - 1][y] == c)
        {
            w.push_back(e - t[x - 1][y] + 1);
            q[x - 1][y] = w.size();
            q[x][y] = w.size();
            u.push_back(s[x][y]);
            return w[w.size() - 1];
        }
        else
        {
            u[q[x][y]] += s[x][y];
            q[x][y] = q[x - 1][y];
            return 0;
        }
    }
    if (arr[x][y] == 'S' || arr[x][y] == 's')
    {
        if (used[x + 1][y] == 0)
        {
            long long ans = dfs(x + 1, y, c, e + 1, b + ((arr[x + 1][y] < 'a') ? 1 : 0));
            q[x][y] = q[x + 1][y];
            return ans;
        }
        else if (used[x + 1][y] == c)
        {
            w.push_back(e - t[x + 1][y] + 1);
            q[x + 1][y] = w.size();
            q[x][y] = w.size();
            u.push_back(s[x][y]);
            return w[w.size() - 1];
        }
        else
        {
            u[q[x][y]] += s[x][y];
            q[x][y] = q[x + 1][y];
            return 0;
        }
    }
}

int main()
{
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    long long n, m, g;
    cin >> n >> m >> g;
    arr.resize(n);
    for (long long i = 0; i < n; i++)
        arr[i].resize(m);
    used.resize(n);
    for (long long i = 0; i < n; i++)
        used[i].resize(m, 0);
    s.resize(n);
    for (long long i = 0; i < n; i++)
        s[i].resize(m, 0);
    q.resize(n);
    for (long long i = 0; i < n; i++)
        q[i].resize(m, 0);
    t.resize(n);
    for (long long i = 0; i < n; i++)
        t[i].resize(m, 0);
    for (long long i = 0; i < n; i++)
    {
        for (long long j = 0; j < m; j++)
            cin >> arr[i][j];
    }
    long long  k = 0;
    long long ans = 0;
    for (long long i = 0; i < n; i++)
    {
        for (long long j = 0; j < m; j++)
        {
            if (used[i][j] == 0)
            {
                k++;
                dfs(i, j, k, 0, (arr[i][j] < 'a') ? 1 : 0);
            }
        }
    }
    for (long long i = 0; i < u.size(); i++)
        ans += min(u[i], w[i]);
    cout << ans << endl;
    return 0;
}
