#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int dp = 0, cp = 3;
int bpx = 0, bpy = 0;
const int N = 100;
char s[N][N];
int n, m;
bool in(int first, int second) {
  return first >= 0 && first < n && second >= 0 && second < m;
}
int L(int first) { return (first + 3) % 4; }
int R(int first) { return (first + 1) % 4; }
int id[N][N];
const int M = N * N * 2;
int px[M][4][4], py[M][4][4], nreg = 0;
int main() {
  int step;
  scanf("%d%d", &n, &step);
  for (int i = (0); i < (int)(n); i++) scanf("%s", s[i]);
  m = strlen(s[0]);
  memset(id, -1, sizeof(id));
  for (int i2 = (0); i2 < (int)(n); i2++)
    for (int j2 = (0); j2 < (int)(m); j2++)
      if (s[i2][j2] != '0' && id[i2][j2] == -1) {
        int i = i2, j = j2;
        while (i + 1 < n && s[i][j] == s[i + 1][j]) ++i;
        while (j + 1 < m && s[i][j] == s[i][j + 1]) ++j;
        for (int k = (0); k < (int)(4); k++) {
          if (dx[k] != 0) {
            for (int u = (0); u < (int)(4); u++)
              px[nreg][k][u] = px[nreg][u][k] = (dx[k] > 0 ? i : i2);
          } else {
            for (int u = (0); u < (int)(4); u++)
              py[nreg][k][u] = py[nreg][u][k] = (dy[k] > 0 ? j : j2);
          }
        }
        for (int ii = (i2); ii <= (int)(i); ii++)
          for (int jj = (j2); jj <= (int)(j); jj++) id[ii][jj] = nreg;
        nreg++;
      }
  int first = 0, second = 0;
  for (int i = (0); i < (int)(step); i++) {
    int dd = id[first][second];
    first = px[dd][dp][cp];
    second = py[dd][dp][cp];
    int nx = first + dx[dp], ny = second + dy[dp];
    if (!in(nx, ny) || s[nx][ny] == '0') {
      if (L(dp) == cp) {
        cp = (cp + 2) % 4;
      } else {
        dp = (dp + 1) % 4;
        cp = L(dp);
      }
    } else {
      first = nx;
      second = ny;
    }
  }
  putchar(s[first][second]);
}
