import java.io.*;
import java.util.*;

public class B1 {
    String fileName = "robots";

    static int[] di = {1, 0, -1, 0};
    static int[] dj = {0, 1, 0, -1};
    static int[][] dir;
    static boolean[][] cont; 
    static int[][] col;
    static int[] q;
    static int[] real;
    static HashMap<Integer, Pair> map;
    
    
    
    static class Pair {
    	int i;
    	int j;
		public Pair(int i, int j) {
			this.i = i;
			this.j = j;
		}
		@Override
		public String toString() {
			return "(" + i + ", " + j + ")";
		}
    }
    
    static void top(int i, int j, int n, int m, int[][] col, ArrayList<Pair> topsort) {
    	col[i][j] = 1;
    	int ni = i + di[dir[i][j]];
    	int nj = j + dj[dir[i][j]];
    	if (ni >= 0 && ni < n && nj >= 0 && nj < m && col[ni][nj] == -1) {
    		top(ni, nj, n, m, col, topsort);
    	}
    	topsort.add(new Pair(i, j));
    }
    
    
    static Pair dfs(int i, int j, int n, int m, int curCol, int[][] col) {
    	col[i][j] = curCol;
    	int ni = i + di[dir[i][j]];
    	int nj = j + dj[dir[i][j]];
    	int q = 0;
    	int real = 0;
    	if (ni >= 0 && ni < n && nj >= 0 && nj < m && col[ni][nj] == -1) {
    		Pair ppp = dfs(ni, nj, n, m, curCol, col);
    		q = ppp.i;
    		real = ppp.j;
    	}
    	return new Pair(q + (cont[i][j] ? 1 : 0), real + 1);
    }
    
    public void solve() throws IOException {
    	int n = nextInt(), m = nextInt(), g = nextInt();
    	if (g == 1) {
    		return;
    	}
    	dir = new int[n][m];
    	cont = new boolean[n][m]; 
    	for (int i = 0; i < n; i++) {
    		String s = nextToken();
			for (int j = 0; j < m; j++) {
				char cur = s.charAt(j);
				if (cur == 'S') {
					dir[i][j] = 0;
					cont[i][j] = true;
				} else if (cur == 's') {
					dir[i][j] = 0;
					cont[i][j] = false;
				} else if (cur == 'E') {
					dir[i][j] = 1;
					cont[i][j] = true;
				} else if (cur == 'e') {
					dir[i][j] = 1;
					cont[i][j] = false;
				} else if (cur == 'N') {
					dir[i][j] = 2;
					cont[i][j] = true;
				} else if (cur == 'n') {
					dir[i][j] = 2;
					cont[i][j] = false;
				} else if (cur == 'W') {
					dir[i][j] = 3;
					cont[i][j] = true;
				} else {
					dir[i][j] = 3;
					cont[i][j] = false;
				}
			}
		}

    	col = new int[n][m];
    	for (int i = 0; i < n; i++) {
			Arrays.fill(col[i], -1);
		}
    	ArrayList<Pair> topsort = new ArrayList<>();
    	for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (col[i][j] == -1) {
					top(i, j, n, m, col, topsort);
				}
			}
		}
    	
    	for (int i = 0; i < n; i++) {
			Arrays.fill(col[i], -1);
		}
    	int sz = topsort.size();
    	q = new int[sz];
    	real = new int[sz];
    	map = new HashMap<>();
    	int curCol = 0;
    	for (int i = 0; i < sz; i++) {
			Pair ccc = topsort.get(i);
			int ci = ccc.i, cj = ccc.j;
			if (col[ci][cj] == -1) {
				Pair res = dfs(ci, cj, n, m, curCol, col);
				int qqq = res.i;
				int rrr = res.j;
				if (rrr == 1) {
					map.put(curCol, ccc);
				}
				q[curCol] = qqq;
				real[curCol] = rrr;
				curCol++;
			}
		}
    	
    	boolean[] isOne = new boolean[curCol];
    	for (int i = 0; i < curCol; i++) {
			isOne[i] = real[i] == 1;
		}
    	
    	for (int i = curCol - 1; i >= 0; i--) {
			if (isOne[i]) {
				Pair ccc = map.get(i);
				int ci = ccc.i, cj = ccc.j;
				int ni = ci + di[dir[ci][cj]];
		    	int nj = cj + dj[dir[ci][cj]];
		    	int fff = -1;
		    	if (ni >= 0 && ni < n && nj >= 0 && nj < m) {
		    		fff = col[ni][nj];
		    	}
		    	q[fff] += q[i];
			}
		}
    	
    	long ans = 0;
    	for (int i = 0; i < curCol; i++) {
			if (real[i] > 1) {
				if (q[i] < real[i]) {
					ans += q[i];
				} else {
					ans += real[i];
				}
			}
		}
    	
    	out.println(ans);
    	
//    	for (int i = 0; i < n; i++) {
//			for (int j = 0; j < m; j++) {
//				System.out.print(col[i][j] + " ");
//			}
//			System.out.println();
//    	}
//    	
//    	for (int i = 0; i < curCol; i++) {
//			System.out.print(q[i] + " ");
//		}
    	
    }

    public void run() {
        try {
            br = new BufferedReader(new FileReader(fileName + ".in")); 
            out = new PrintWriter(fileName + ".out");

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

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

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

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

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new B1().run();
    }

}