import sys
from threading import *
sys.setrecursionlimit(10 ** 9)
stack_size(2 ** 27)



def main():
    inf = open("robots.in", "r")
    outf = open("robots.out", "w")
    n, m, p = map(int, inf.readline().split())
    lst = []
    for i in range(n):
        lst.append(list(map(str, inf.readline().split()))[0])
     
    grp = []
    cr = 0
    for i in range(n):
        for j in range(m):
            if lst[i][j] == 'S' or lst[i][j] == 's':
                k = cr + m
            if lst[i][j] == 'N' or lst[i][j] == 'n':
                k = cr - m
            if lst[i][j] == 'W' or lst[i][j] == 'w':
                k = cr - 1
            if lst[i][j] == 'E' or lst[i][j] == 'e':
                k = cr + 1
            grp.append(k)
            cr += 1
    used = [0] * (m * n)
    sna = 0
    def dfs(v):
        used[v] = 1
        if used[grp[v]] == 0:
            ans = dfs(grp[v])
            if ans[2] != 1:
                ans[0] += 1
                if v == ans[1]:
                    sna = ans[0]
                    ans[2] = 1
            else:
                return ans
        else:
            if used[grp[v]] == 1:
                ans = [1, grp[v], 0]
        return ans
     
     
    crrans = 0
    for i in range(len(used)):
        if used[i] == 0:
            sna = dfs(i)
            if sna[2] == 1:
                crrans += sna[0]
    outf.write(str(crrans))
    outf.close()
    

t = Thread(target=main())
t.start()