import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class B {
	static int n, m, g;
	static int[][][] adjArray;
	static boolean[][] robots;

	static void read() throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("robots.in"));
		StringTokenizer st = new StringTokenizer(in.readLine());
		n = Integer.parseInt(st.nextToken());
		m = Integer.parseInt(st.nextToken());
		g = Integer.parseInt(st.nextToken());
		adjArray = new int[n][m][2];
		robots = new boolean[n][m];
		for (int i = 0; i < n; i++) {
			char[] line = in.readLine().toCharArray();
			for (int j = 0; j < m; j++) {
				int newI = i;
				int newJ = j;
				robots[i][j] = ('A' <= line[j]) && (line[j] <= 'Z');
				if (line[j] == 'N' || line[j] == 'n') {
					newI--;
				} else if (line[j] == 'S' || line[j] == 's') {
					newI++;
				} else if (line[j] == 'W' || line[j] == 'w') {
					newJ--;
				} else if (line[j] == 'E' || line[j] == 'e') {
					newJ++;
				}
				int[] tmp = { newI, newJ };
				adjArray[i][j] = tmp;
			}
		}
		in.close();
	}

	static int[][] colors;

	static void coloring(int[] v, int color) {
		ArrayList<int[]> stack = new ArrayList<>();
		stack.add(v);
		while (!stack.isEmpty()) {
			int[] u = stack.get(stack.size() - 1);
			if (colors[u[0]][u[1]] == 0) {
				colors[u[0]][u[1]] = color;
				stack.add(adjArray[u[0]][u[1]]);
			} else if (colors[u[0]][u[1]] == color) {
				int[] last = stack.remove(stack.size() - 1);
				do {
					colors[last[0]][last[1]] = -color;
					if (stack.size() == 0)
						break;
					last = stack.remove(stack.size() - 1);
				} while (!Arrays.equals(u, last));
				break;
			} else {
				int newColor = Math.abs(colors[u[0]][u[1]]);
				while (!stack.isEmpty()) {
					int[] last = stack.remove(stack.size() - 1);
					if (colors[last[0]][last[1]] == color)
						colors[last[0]][last[1]] = newColor;
				}
			}
		}
	}

	public static void main(String[] args) throws IOException {
		read();
		if (g == 1)
			return;
		colors = new int[n][m];
		int color = 1;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (colors[i][j] == 0) {
					int[] v = { i, j };
					coloring(v, color);
					color = colors[i][j] + 1;
				}
			}
		}
		// for (int i = 0; i < colors.length; i++)
		// System.out.println(Arrays.toString(colors[i]));
		int[] numRobots = new int[color + 1];
		int[] lenCycle = new int[color + 1];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (colors[i][j] < 0) {
					lenCycle[-colors[i][j]]++;
				}
				if (robots[i][j])
					numRobots[Math.abs(colors[i][j])]++;
			}
		}
		int ans = 0;
		for (int i = 0; i <= color; i++) {
			ans += Math.min(lenCycle[i], numRobots[i]);
		}
		PrintWriter out = new PrintWriter("robots.out");
		out.println(ans);
		out.close();
	}

}
