fin = open('robots.in')
fout = open('robots.out', 'w')
n, m, g = map(int, fin.readline().split())
ANS1 = []
ANS2 = []
A = [0] * n
c = 0
B = [[-1] * m for i in range(n)]
for i in range(n):
    A[i] = fin.readline()
for i in range(n):
    for j in range(m):
        if ord(A[i][j]) < 97:
            Q = set()
            Q.add((i, j))
            x = i
            y = j
            if A[x][y] == 'N':
                x -= 1
            elif A[x][y] == 'S':
                x += 1
            elif A[x][y] == 'W':
                y -= 1
            else:
                y += 1            
            while (x, y) not in Q:
                Q.add((x, y))
                if A[x][y] == 'N':
                    x -= 1
                elif A[x][y] == 'S':
                    x += 1
                elif A[x][y] == 'W':
                    y -= 1
                else:
                    y += 1
            X = x
            Y = y
            if B[x][y] == -1:
                ANS1.append(1)
                ans = 1
                B[x][y] = c
                if A[x][y] == 'N':
                    x -= 1
                elif A[x][y] == 'S':
                    x += 1
                elif A[x][y] == 'W':
                    y -= 1
                else:
                    y += 1            
                while (x, y) != (X, Y):
                    ans += 1
                    B[x][y] = c                
                    if A[x][y] == 'N':
                        x -= 1
                    elif A[x][y] == 'S':
                        x += 1
                    elif A[x][y] == 'W':
                        y -= 1
                    else:
                        y += 1
                c += 1
                ANS2.append(ans)
            else:
                ANS1[B[x][y]] += 1
ans = 0
for i in range(len(ANS1)):
    ans += min(ANS1[i], ANS2[i])
fout.write(str(ans))
fin.close()
fout.close()