#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <set>
#include <map>
 
using namespace std;
 
#define int long long
map <char, pair <int, int> > mmm;
int used[2000][2000];
int est[2000][2000];
int num[2000][2000];
pair <int, int> mas[2000][2000];
vector <pair <int, int> > cur;
int curnum = 0;
void dfs(pair <int, int> v) {
    cur.push_back(v);
    pair <int, int> to = mas[v.first][v.second];
    used[v.first][v.second] = 1;
    if (used[to.first][to.second]) {
        if (num[to.first][to.second] == 0) {
            curnum += 1;
            for (auto it : cur) {
                num[it.first][it.second] = curnum;
            }
        }
        else {
            for (auto it : cur) {
                num[it.first][it.second] = num[to.first][to.second];
            }
        }
    }
    else {
        dfs(to);
    }
}
vector <vector <pair <int, int> > > tt;
int col[2000000];
int dfs2(pair <int, int> v) {
    used[v.first][v.second] = 1;
    cur.push_back(v);
    pair <int, int> to = mas[v.first][v.second];
    if (used[to.first][to.second]) {
        int ind = cur.size() - 1;
        while (cur[ind] != to) {
            ind--;
        }
        return cur.size() - ind;
    }
    return dfs2(to);
}
signed main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
     
    int n, m, g;
    cin >> n >> m >> g;
    mmm['s'] = make_pair(1, 0);
    mmm['w'] = make_pair(0, -1);
    mmm['e'] = make_pair(0, 1);
    mmm['n'] = make_pair(-1, 0);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            char c;
            cin >> c;
            if (c >= 'A' && c <= 'Z') {
                est[i][j] = 1;
                c -= 'A' - 'a';
            }
             
            mas[i][j] = make_pair(i + mmm[c].first, j + mmm[c].second);
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (!used[i][j]) {
                cur.clear();
                dfs(make_pair(i, j));
            }
        }
    }
    tt.resize(curnum + 1);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            tt[num[i][j]].push_back(make_pair(i, j));
        }
    }
    for (int i = 1; i <= curnum; ++i) {
        for (auto it : tt[i]) {
            col[i] += est[it.first][it.second];
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            used[i][j] = 0;
        }
    }
    for (int i = 1; i <= curnum; ++i) {
        cur.clear();
        ans += min(col[i], dfs2(tt[i][0]));
    }
    cout << ans << endl;
}