#include <bits/stdc++.h>
using namespace std;
bool v[60][60][4];
int a[60][60];
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
int ans[3600 * 4];
int main() {
  int m, n, l;
  cin >> m >> n;
  for (int i = 0; i < m; i++) {
    char s[60];
    cin >> s;
    l = strlen(s);
    for (int j = 0; j < l; j++) a[i][j] = s[j] - '0';
  }
  int x = 0, y = 0, d = 0, na = 0;
  while (!v[x][y][d]) {
    v[x][y][d] = 1;
    int tx = x + dx[d], ty = y + dy[d], flag = 1;
    while (tx < 0 || tx >= m || ty < 0 || ty >= l || !a[tx][ty]) {
      d = (d + 1) % 4;
      if (v[x][y][d]) flag = 0;
      v[x][y][d] = 1;
      ans[na++] = a[x][y];
      ans[na++] = a[x][y];
      if (!flag) break;
      tx = x + dx[d], ty = y + dy[d];
    }
    if (!flag) break;
    x = tx, y = ty;
    ans[na++] = a[x][y];
  }
  for (int i = 0; i < na; i++) cout << ans[i];
  cout << endl;
  cout << na << endl;
  cout << ans[(n - 1) % na] << endl;
  return 0;
}
