#include <bits/stdc++.h>
using namespace std;
int n, m, cmd;
string mp[100];
int mark[100][100];
int ptr = 1;
int bound[20000][4];
int nxt[20000][4][2][3];
int main() {
  cin >> n >> cmd;
  for (int i = 0; i < n; i++) cin >> mp[i];
  m = mp[0].length();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mp[i][j] >= '1' && !mark[i][j]) {
        int ii = i;
        while (ii < n && mp[ii][j] == mp[i][j]) ii++;
        ii--;
        int jj = j;
        while (jj < m && mp[i][jj] == mp[i][j]) jj++;
        jj--;
        bound[ptr][0] = i;
        bound[ptr][1] = j;
        bound[ptr][2] = ii;
        bound[ptr][3] = jj;
        for (int k = i; k <= ii; k++) {
          for (int l = j; l <= jj; l++) {
            mark[k][l] = ptr;
          }
        }
        ptr++;
      }
    }
  }
  for (int i = 1; i < ptr; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 2; k++) {
        int r = 0, c = 0;
        if (j == 0) {
          if (k == 0)
            r = bound[i][0], c = bound[i][3] + 1;
          else
            r = bound[i][2], c = bound[i][3] + 1;
        } else if (j == 1) {
          if (k == 0)
            r = bound[i][2] + 1, c = bound[i][3];
          else
            r = bound[i][2] + 1, c = bound[i][1];
        } else if (j == 2) {
          if (k == 0)
            r = bound[i][2], c = bound[i][1] - 1;
          else
            r = bound[i][0], c = bound[i][1] - 1;
        } else {
          if (k == 0)
            r = bound[i][0] - 1, c = bound[i][1];
          else
            r = bound[i][0] - 1, c = bound[i][3];
        }
        if (r >= 0 && c >= 0 && r < n && c < m && mark[r][c]) {
          nxt[i][j][k][0] = mark[r][c];
          nxt[i][j][k][1] = j;
          nxt[i][j][k][2] = k;
        } else {
          if (k == 0) {
            nxt[i][j][k][0] = i;
            nxt[i][j][k][1] = j;
            nxt[i][j][k][2] = 1;
          } else {
            nxt[i][j][k][0] = i;
            nxt[i][j][k][1] = (j + 1) % 4;
            nxt[i][j][k][2] = 0;
          }
        }
      }
    }
  }
  int i = 1, j = 0, k = 0;
  for (int step = 0; step < cmd; step++) {
    int ni = nxt[i][j][k][0];
    int nj = nxt[i][j][k][1];
    int nk = nxt[i][j][k][2];
    i = ni, j = nj, k = nk;
  }
  cout << mp[bound[i][0]][bound[i][1]] << endl;
  return 0;
}
