MatrixSize = eval(input())
Direction = eval(input())
Matrix = []
for i in range(MatrixSize):
Matrix.append([eval(j) for j in input().split()])
start = (MatrixSize - 1) // 2
x, y = start, start
i = 1
while x >= 0 and y >= 0:
for j in range(2):
if x < 0 or y < 0:
break
for k in range(i):
print(Matrix[x][y], end = '')
if Direction == 0:
y -= 1
elif Direction == 1:
x -= 1
elif Direction == 2:
y += 1
else:
x += 1
Direction = (Direction + 1) % 4
i += 1