f = open('robots.in', 'r')
ff = open('robots.out', 'w')
n, m, g = map(int, f.readline().split())
used = [[False for i in range(m)] for j in range(n)]
g = [list(f.readline().rstrip()) for i in range(n)]
tp = []
def top(x, y):
    global tp
    used[x][y] = True
    if g[x][y] == 'S' and (not used[x + 1][y]):
        top(x + 1, y)
    elif g[x][y] == 'N' and (not used[x - 1][y]):
        top(x - 1, y)
    elif g[x][y] == 'W' and (not used[x][y - 1]):
        top(x, y - 1)
    elif g[x][y] == 'E' and (not used[x][y + 1]):
        top(x, y + 1)
    tp.append([x, y])
for i in range(n):
    for j in range(m):
        if not used[i][j]:
            top(i, j)
'''for i in range(n):
    for j in range(m):
        if g[i][j] == 'S':
            g[i][j] = 'N'
        elif g[i][j] == 'N':
            g[i][j] = 'S'
        elif g[i][j] == 'W':
            g[i][j] = 'E'
        else:
            g[i][j] == 'W'
'''
used = [[False for i in range(m)] for j in range(n)]
ans = []
def dfs(x, y):
    global ans
    used[x][y] = True
    ans.append([x, y])
    if y < m - 1 and g[x][y + 1] == 'W' and used[x][y + 1] == False:
        dfs(x, y + 1)
    if y > 0     and g[x][y - 1] == 'E' and used[x][y - 1] == False:
        dfs(x, y - 1)
    if x < n - 1 and g[x + 1][y] == 'N' and used[x][y + 1] == False:
        dfs(x + 1, y)
    if x > 0     and g[x - 1][y] == 'S' and used[x - 1][y] == False:
        dfs(x - 1, y)
sm = 0
for elem in tp[::-1]:
    ans = []
    if not used[elem[0]][elem[1]]:
        dfs(elem[0], elem[1])
    if len(ans) > 1:
        sm += len(ans)
print(sm, file = ff)
ff.close()
