#include <bits/stdc++.h>
using namespace std;
char a[55][55];
int n, m, k, dp, ci, cj, cp;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int go[55][55][4][4][4];
int main() {
  cin >> n >> k;
  for (int i = 0; i < 55; ++i) {
    a[0][i] = a[n + 1][i] = '0';
  }
  string s;
  for (int i = 1; i <= n; ++i) {
    cin >> s;
    for (int j = 1; j <= (int)s.size(); ++j) a[i][j] = s[j - 1];
    a[i][0] = a[i][(int)s.size() + 1] = '0';
  }
  m = (int)s.size();
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      for (int ddp = 0; ddp < 4; ++ddp)
        for (int ccp = 1; ccp <= 3; ccp += 2) {
          ci = i;
          cj = j;
          dp = ddp;
          cp = ccp;
          int d2 = (dp + cp) % 4;
          int oi = ci, oj = cj;
          while (a[ci + dx[dp]][cj + dy[dp]] == a[ci][cj]) {
            ci += dx[dp];
            cj += dy[dp];
          }
          while (a[ci + dx[d2]][cj + dy[d2]] == a[ci][cj]) {
            ci += dx[d2];
            cj += dy[d2];
          }
          if (a[ci + dx[dp]][cj + dy[dp]] != '0') {
            ci += dx[dp];
            cj += dy[dp];
          } else if (cp == 3) {
            ci = oi;
            cj = oj;
            cp = 1;
          } else {
            ci = oi;
            cj = oj;
            dp = (dp + 1) % 4;
            cp = 3;
          }
          go[i][j][ddp][ccp][0] = ci;
          go[i][j][ddp][ccp][1] = cj;
          go[i][j][ddp][ccp][2] = dp;
          go[i][j][ddp][ccp][3] = cp;
        }
  ci = cj = 1;
  cp = 3;
  dp = 0;
  while (k--) {
    int ni = go[ci][cj][dp][cp][0];
    int nj = go[ci][cj][dp][cp][1];
    int nd = go[ci][cj][dp][cp][2];
    int nc = go[ci][cj][dp][cp][3];
    ci = ni;
    cj = nj;
    dp = nd;
    cp = nc;
  }
  cout << a[ci][cj] << endl;
}
