n,m = list(map(int, input().strip().split(" ")))
qipan = []
for _ in range(n):
qipan.append(list(input().strip()))
x,y = list(map(int, input().strip().split(" ")))
res = 0
def move(qipan, x, y, tmp=None):
global res
if x < 0 or x > n or y < 0 or y > m:
return
k = qipan[x][y]
if k == 'E':
qipan[x][y] = '.'
move(qipan, x, y+1, 'E')
elif k == 'N':
qipan[x][y] = '.'
move(qipan, x-1, y, 'N')
elif k == 'W':
qipan[x][y] = '.'
move(qipan, x, y-1, 'W')
elif k == 'S':
qipan[x][y] = '.'
move(qipan, x+1, y, 'S')
elif k == '.':
if tmp == 'E':
move(qipan, x, y+1, tmp)
elif tmp == 'N':
move(qipan, x-1, y, tmp)
elif tmp == 'W':
move(qipan, x, y-1, tmp)
elif tmp == 'S':
move(qipan, x+1, y, tmp)
# res += 1
res += 1
res = move(qipan, x, y)
print(res)
#笔试题目##百度##测试开发工程师#