import java.io.*;
import java.util.Arrays;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

/**
 * Created by roi on 05.04.2016.
 */
public class Task2 {

    int n, m;
    boolean g;
    char[][] field;

    void solve(IO io) {
        n = io.nextInt();
        m = io.nextInt();
        g = io.nextInt() == 1;

        time = new int[n][m];
        cycle = new int[n][m];
        visited = new boolean[n][m];

        field = new char[n][m];
        for (int i = 0; i < n; i++) {
            field[i] = io.readLine().toCharArray();
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (!visited[i][j] && isRobot(i, j)) {
                    go(i, j, 1);

                    for (int k = 0; k < n; k++) {
                        Arrays.fill(time[k], 0);
                    }
                    timer = 1;
                }
            }
        }

        for (int i = 0; i < n; i++) {
            Arrays.fill(visited[i], false);
        }

        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (!visited[i][j] && cycle[i][j] != 0) {
                    ans++;
                }
            }
        }
        io.println(ans);
    }

    int[][] time;
    boolean[][] visited;
    int timer = 1;

    int[] len;

    int[][] cycle;
    int curCycle = 1;

    int go(int i, int j, int curCnt) { // returns time after which cycle = true
        visited[i][j] = true;

        if (time[i][j] != 0) {
            cycle[i][j] = curCycle;
            return time[i][j];
        }
        if (isRobot(i, j)) {
            curCnt++;
        }

        time[i][j] = timer++;
        char move = field[i][j];
        int ni = moveI(i, move);
        int nj = moveJ(j, move);

        int t = go(ni, nj, curCnt);
        if (time[i][j] >= t) {
            cycle[i][j] = curCycle;
        }
        return t;
    }

    int moveI(int i, char move) {
        move = Character.toUpperCase(move);
        if (move == 'N') return i - 1;
        if (move == 'S') return i + 1;
        return i;
    }

    int moveJ(int j, char move) {
        move = Character.toUpperCase(move);
        if (move == 'W') return j - 1;
        if (move == 'E') return j + 1;
        return j;
    }

    boolean isValid(int i, int j) {
        return 0 <= i && 0 <= j && i < n && j < m;
    }


    boolean isRobot(int i, int j) {
        return field[i][j] == Character.toUpperCase(field[i][j]);
    }


    public static void main(String[] args) {
        Task2 solver = new Task2();
        IO io = new IO("robots");
        solver.solve(io);
        io.out.close();
    }

    static class IO {
        BufferedReader in;
        StringTokenizer tok;
        PrintWriter out;

        IO(String file) {
            try {
                in = new BufferedReader(new FileReader(file + ".in"));
                out = new PrintWriter(file + ".out");
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        String readLine() {
            try {
                return in.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

        String nextToken() {
            if (tok == null || !tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
            return tok.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        int[] readIntArray(int len) {
            int[] res = new int[len];
            for (int i = 0; i < len; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        void println(long x) {
            out.println(x);
        }
    }

}
