import sys
input = sys.stdin.readline
from collections import deque
n, m = map(int,input().split())
r, c, d = map(int,input().split())
area = [[0]*m for _ in range(n)]
count = 0
for i in range(n):
area[i] = list(map(int,input().split()))
def dfs(x,y,d):
global count
nx = [0]*4
ny = [0]*4
if area[x-1][y] != 0 and area[x+1][y] != 0 and area[x][y-1] != 0 and area[x][y+1] != 0:
if (d == 0 and area[x+1][y] == 1) or (d==1 and area[x][y-1] == 1) or (d==2 and area[x-1][y]==1) or (d==3 and area[x][y+1]==1) :
print(count)
sys.exit()
if area[x][y] == 0:
area[x][y] = 2
count+=1
if d == 0:
nx = [0,1,0,-1]
ny = [-1,0,1,0]
elif d == 1:
nx = [-1,0,1,0]
ny = [0,-1,0,1]
elif d == 2:
nx = [0,-1,0,1]
ny = [1, 0,-1,0]
elif d == 3:
nx = [1,0,-1,0]
ny = [0, 1, 0,-1]
for i in range(4):
temp_x = x + nx[i]
temp_y = y + ny[i]
if temp_x >= 0 and temp_x < n and temp_y >= 0 and temp_y < m:
if area[temp_x][temp_y] == 0:
next_x = nx[i]
next_y = ny[i]
if next_x == -1 and next_y == 0:
dfs(temp_x,temp_y,0)
elif next_x == 1 and next_y == 0:
dfs(temp_x,temp_y,2)
elif next_x == 0 and next_y == -1:
dfs(temp_x,temp_y,3)
elif next_x == 0 and next_y == 1:
dfs(temp_x,temp_y,1)
dfs(r,c,d)
print(count)