#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const double dinf = 1e200;
void ext(int c) {}
char src[100][100];
int ind[100][100];
int anya[10000];
int anyb[10000];
int da[4] = {0, 1, 0, -1};
int db[4] = {1, 0, -1, 0};
int go[10000 * 8];
int n;
int K;
int main() {
  cin >> n >> K;
  gets(src[0]);
  for (int i = 0; i < (n); ++i) gets(src[i + 1] + 1);
  memset(ind, -1, sizeof(ind));
  int c = 0;
  int m = strlen(src[1] + 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (ind[i][j] != -1 || src[i][j] == '0') continue;
      anya[c] = i;
      anyb[c] = j;
      for (int a = i; src[a][j] == src[i][j]; ++a)
        for (int b = j; src[a][b] == src[i][j]; ++b) ind[a][b] = c;
      ++c;
    }
  }
  for (int p = 0; p < (c); ++p) {
    for (int ds = 0; ds < (8); ++ds) {
      int d = ds / 2;
      int dd = (d + (ds % 2 * 2 - 1) + 4) % 4;
      int a = anya[p];
      int b = anyb[p];
      while (src[a + da[d]][b + db[d]] == src[a][b]) a += da[d], b += db[d];
      while (src[a + da[dd]][b + db[dd]] == src[a][b]) a += da[dd], b += db[dd];
      int ni = ind[a + da[d]][b + db[d]];
      if (ni == -1)
        go[p * 8 + ds] = p * 8 + (ds + 1) % 8;
      else
        go[p * 8 + ds] = ni * 8 + ds;
    }
  }
  int v = ind[1][1] * 8 + 0;
  for (int i = 0; i < (K); ++i) v = go[v];
  cout << src[anya[v / 8]][anyb[v / 8]];
  return 0;
}
