def Print for in range for in range print end print end def Hod if i2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def Print(a):
for i in range(m + 2):
for j in range(n + 2):
print('4%d' % a[i][j], end = ' ')
print('\n', end = ' ')
def Hod(a, i, j, d):
a[i][j] = d
if i == i2 and j == j2:
Print(a)
return
else:
for k in range(4):
if a[i + dx[k]][j + dy[k]] == 0:
Hod(a, i + dx[k], j + dy[k], d + 1)
a[i][j] = 0
n, m = map(int, input().split())
dx = [-1, 0, 0, 1]; dy = [0, -1, 1, 0]
a = [[0]*(n + 2) for i in range(m + 2)]
f = open('labirint.txt', 'r')
for i in range(m + 2):
a[i] = list(map(int, f.readlines().split()))
Print(a)
f.close()
i1, j1 = map(int, input().split())
i2, j2 = map(int, input().split())
Hod(a, i1, j1, 1)
if a[i2][j2] == 0:
print('no prohod')