#include <iostream>
#include <vector>
#define N 50
using namespace std;
int map[N][N];
vector<int> ans;
int main(){
int n, dir, d[4][2]={{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
while (cin >> n){
cin >> dir;
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
cin >> map[i][j];
}
}
int x=n/2, y=n/2;
int steps=1;
int walk=0;
int keep=0;
ans.clear();
while (x>=0 && y>=0 && x<n && y<n){
ans.push_back(map[x][y]);
if (walk==steps){
dir=(dir+1)%4;
walk=0;
keep++;
if (keep==2){
steps++;
keep=0;
}
}
x+=d[dir][0];
y+=d[dir][1];
walk++;
}
for (int i=0; i<ans.size(); i++){
cout <<ans[i];
}
cout <<endl;
}
}