#include <bits/stdc++.h>
char s[64][64];
int d[4][64][64];
int n, m, K;
int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int main() {
  int i, j, k, d1, d2, x, y;
  scanf("%d %d", &n, &K);
  for (i = 0; i < n; i++) scanf("%s", s[i]);
  m = strlen(s[0]);
  for (i = 0; i < n; i++)
    for (d[0][i][m - 1] = 1, j = m - 2; j >= 0; j--) {
      if (s[i][j + 1] == s[i][j])
        d[0][i][j] = d[0][i][j + 1] + 1;
      else
        d[0][i][j] = 1;
    }
  for (i = 0; i < m; i++)
    for (d[1][n - 1][i] = 1, j = n - 2; j >= 0; j--) {
      if (s[j][i] == s[j + 1][i])
        d[1][j][i] = d[1][j + 1][i] + 1;
      else
        d[1][j][i] = 1;
    }
  for (i = 0; i < n; i++)
    for (d[2][i][0] = 1, j = 1; j < m; j++) {
      if (s[i][j] == s[i][j - 1])
        d[2][i][j] = d[2][i][j - 1] + 1;
      else
        d[2][i][j] = 1;
    }
  for (i = 0; i < m; i++)
    for (d[3][0][i] = 1, j = 1; j < n; j++) {
      if (s[j][i] == s[j - 1][i])
        d[3][j][i] = d[3][j - 1][i] + 1;
      else
        d[3][j][i] = 1;
    }
  x = y = d1 = d2 = 0;
  for (i = 0; i < K; i++) {
    int nx = x + dir[d1][0] * (d[d1][x][y] - 1);
    int ny = y + dir[d1][1] * (d[d1][x][y] - 1);
    int px, py;
    if (!d2) {
      px = nx + dir[(d1 + 3) % 4][0] * (d[(d1 + 3) % 4][nx][ny] - 1);
      py = ny + dir[(d1 + 3) % 4][1] * (d[(d1 + 3) % 4][nx][ny] - 1);
    } else {
      px = nx + dir[(d1 + 1) % 4][0] * (d[(d1 + 1) % 4][nx][ny] - 1);
      py = ny + dir[(d1 + 1) % 4][1] * (d[(d1 + 1) % 4][nx][ny] - 1);
    }
    nx = px + dir[d1][0], ny = py + dir[d1][1];
    if (nx >= n || nx < 0 || ny >= m || ny < 0 || s[nx][ny] == '0') {
      if (!d2)
        d2 = 1;
      else
        d2 = 0, d1 = (d1 + 1) % 4;
    } else
      x = nx, y = ny;
  }
  printf("%c\n", s[x][y]);
  return 0;
}
