from collections import deque
n, k = map(int, input().split())
graph = []
data = []
for i in range(n):
    graph.append(list(map(int, input().split())))
    for j in range(n):
        if graph[i][j] != 0:
            data.append(graph[i][j], 0, i, j)
data.sort()
q = deque(data)
S, X, Y = map(int, input().split())
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
while q:
    virus, s, x, y = q.popleft()
    if s == S:
        break
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if -1 < nx < n and -1 < ny < n:
            if graph[nx][ny] == 0:
                graph[nx][ny] = virus
                q.append(virus, s + 1, nx, ny)
print(graph[X - 1][Y - 1])

8c74ab6df57fd4f19e1a443d4d7f2a4e7c9764cb
<mask token>

<mask token>
for i in range(n):
    graph.append(list(map(int, input().split())))
    for j in range(n):
        if graph[i][j] != 0:
            data.append(graph[i][j], 0, i, j)
data.sort()
<mask token>
while q:
    virus, s, x, y = q.popleft()
    if s == S:
        break
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if -1 < nx < n and -1 < ny < n:
            if graph[nx][ny] == 0:
                graph[nx][ny] = virus
                q.append(virus, s + 1, nx, ny)
print(graph[X - 1][Y - 1])

<mask token>
n, k = map(int, input().split())
graph = []
data = []
for i in range(n):
    graph.append(list(map(int, input().split())))
    for j in range(n):
        if graph[i][j] != 0:
            data.append(graph[i][j], 0, i, j)
data.sort()
q = deque(data)
S, X, Y = map(int, input().split())
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
while q:
    virus, s, x, y = q.popleft()
    if s == S:
        break
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if -1 < nx < n and -1 < ny < n:
            if graph[nx][ny] == 0:
                graph[nx][ny] = virus
                q.append(virus, s + 1, nx, ny)
print(graph[X - 1][Y - 1])

from collections import deque
n, k = map(int, input().split())
graph = []
data = []
for i in range(n):
    graph.append(list(map(int, input().split())))
    for j in range(n):
        if graph[i][j] != 0:
            data.append(graph[i][j], 0, i, j)
data.sort()
q = deque(data)
S, X, Y = map(int, input().split())
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
while q:
    virus, s, x, y = q.popleft()
    if s == S:
        break
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if -1 < nx < n and -1 < ny < n:
            if graph[nx][ny] == 0:
                graph[nx][ny] = virus
                q.append(virus, s + 1, nx, ny)
print(graph[X - 1][Y - 1])
