uses Math,SysUtils;
type longint=int64;
     mass=array[-1..5000000] of longint;
     maxx=array[-1..5000,-1..5000] of longint;
     matt=array[-1..5000000,0..5] of longint;
var m1,used,m4,used1,used2,com,kolv:mass;
    m:maxx;
    r:matt;
    ch:char;
    res:int64;
    a, b, c,  n, k,g, kol,j:longint;
    u:boolean;
    i,z:integer;
const x:array[1..4] of longint = ( 1,0,-1,0 );
const y:array[1..4] of longint = ( 0,-1,0,1 );
procedure dfs(x:longint);
var j:integer;
Begin
	used[x]:=kol;
	inc(com[kol],m1[x]);
	for j:=1 to r[x,0] do
		if used[r[x,j]]=0
		then dfs(r[x][j]);
end;
procedure dfs1(x:longint);
Begin
	used2[x] := 1;
	if (used2[m4[x]]= 1)
	then Begin
          u := true;
          b := m4[x];
          inc(kolv[used[x]]);
          exit;
       end
	else dfs1(m4[x]);
	if (u)
	then inc(kolv[used[x]]);
	if (x = b)
  then u:=false;
end;
Begin
 //	assign(input,'input.txt');
 //	assign(output, 'output.txt');
	assign(input,'robots.in');
 	assign(output, 'robots.out');
	readln(n,k,g);
	for i:=1 to n  do
    Begin
      for z:=1 to k do
         Begin
             read(ch);
             if (ch in ['W','S','E','N'])
             then m1[(i-1)*k+z] := 1;
             if (ch in ['S','s'])
             then m[i,z]:= 1
             else if (ch in ['W','w'])
                  then m[i][z] := 2
                  else if (ch in ['N','n'])
                       then m[i][z] := 3
                       else m[i][z] := 4;
              inc(r[(i - 1)*k + z,0]);
              r[(i - 1)*k + z,r[(i - 1)*k + z,0]]:=((i + x[m[i][z]] - 1)*k + (z+y[m[i][z]]));
              m4[(i - 1)*k + z] := r[(i - 1)*k + z,1];
            end;
      readln;
    end;
	for i:=1 to n do
	Begin
    for z:=1 to k do
		Begin
			if (m[i][z - 1] = 4)
      then Begin
               inc(r[(i - 1)*k + z,0]);
				       r[(i - 1)*k + z,r[(i - 1)*k + z,0]]:=(i - 1)*k + z - 1;
           end;
      if (m[i-1][z] = 1)
      then Begin
               inc(r[(i - 1)*k + z,0]);
				       r[(i - 1)*k + z,r[(i - 1)*k + z,0]]:=(i - 2)*k + z;
           end;
      if (m[i][z + 1] = 2)
      then Begin
               inc(r[(i - 1)*k + z,0]);
				       r[(i - 1)*k + z,r[(i - 1)*k + z,0]]:=(i - 1)*k + z + 1;
           end;
      if (m[i + 1][z] = 3)
      then Begin
               inc(r[(i - 1)*k + z,0]);
				       r[(i - 1)*k + z,r[(i - 1)*k + z,0]]:=i*k + z;
           end;
		end;
	end;
  res:=0;
  kol:=0;
	for i:=1 to n*k do
		if (used[i] = 0) and (m1[i]=1)
		then Begin
           inc(kol);
           dfs(i);
         end;
	for i:=1 to n*k do
		if (used1[used[i]] = 0) and (m1[i]=1)
		then Begin
            used1[used[i]] := 1;
            b := 0;
            u := false;
            dfs1(i);
         end;
	for i:=1 to kol do
		res := res+min(com[i], kolv[i]);
	writeln(res);
end. 
