#include <bits/stdc++.h>
using namespace std;
int n, m, t;
char a[111][111];
int c[111][111];
int g[11111][4][2];
int out[11111];
int col(int i, int j) {
  if (i < 0 || j < 0 || i >= n || j >= m) return '0';
  return a[i][j];
}
int cc(int i, int j) {
  if (i < 0 || j < 0 || i >= n || j >= m) return 0;
  return c[i][j];
}
int main() {
  scanf("%d%d\n", &n, &t);
  for (int i = 0; i < n; ++i) scanf("%s", a[i]);
  m = strlen(a[0]);
  int k = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (col(i, j) != '0') {
        if (col(i - 1, j) == col(i, j)) {
          c[i][j] = c[i - 1][j];
        } else if (col(i, j - 1) == col(i, j)) {
          c[i][j] = c[i][j - 1];
        } else {
          c[i][j] = ++k;
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int v = c[i][j];
      out[v] = col(i, j);
      if (col(i - 1, j) != col(i, j) && col(i, j - 1) != col(i, j)) {
        g[v][3][0] = cc(i - 1, j);
        g[v][2][1] = cc(i, j - 1);
      }
      if (col(i - 1, j) != col(i, j) && col(i, j + 1) != col(i, j)) {
        g[v][3][1] = cc(i - 1, j);
        g[v][0][0] = cc(i, j + 1);
      }
      if (col(i + 1, j) != col(i, j) && col(i, j + 1) != col(i, j)) {
        g[v][1][0] = cc(i + 1, j);
        g[v][0][1] = cc(i, j + 1);
      }
      if (col(i + 1, j) != col(i, j) && col(i, j - 1) != col(i, j)) {
        g[v][1][1] = cc(i + 1, j);
        g[v][2][0] = cc(i, j - 1);
      }
    }
  }
  int bp = cc(0, 0), dp = 0, cp = 0;
  while (t--) {
    if (g[bp][dp][cp] == 0) {
      if (cp == 0)
        ++cp;
      else {
        cp = 0;
        dp = (dp + 1) % 4;
      }
    } else {
      bp = g[bp][dp][cp];
    }
  }
  cout << (char)out[bp] << endl;
  return 0;
}
