#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
void minn(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
void maxx(T &a, T b) {
  if (a < b) a = b;
}
int madd(int &a, int b) {
  a += b;
  if (a >= 1000000009) a -= 1000000009;
  return a;
}
int msub(int &a, int b) {
  a -= b;
  if (a < 0) a += 1000000009;
  return a;
}
int mmult(int &a, int b) { return a = (long long)a * b % 1000000009; }
int mdiv(long long a, long long b, long long m) {
  a = (a % 1000000009 + 1000000009) % 1000000009;
  b = (b % 1000000009 + 1000000009) % 1000000009;
  if (a % b == 0) return a / b;
  return (a + m * mdiv(-a, m, b)) / b;
}
int DX[4] = {0, 1, 0, -1};
int DY[4] = {1, 0, -1, 0};
int n, m, l;
char C[55][55];
pair<int, int> P[55][55], PP[55][55];
pair<int, int> color(int i, int j) {
  if (P[i][j].first == i && P[i][j].second == j)
    return P[i][j];
  else
    return P[i][j] = color(P[i][j].first, P[i][j].second);
}
pair<int, int> colorr(int i, int j) {
  if (PP[i][j].first == i && PP[i][j].second == j)
    return PP[i][j];
  else
    return PP[i][j] = colorr(PP[i][j].first, PP[i][j].second);
}
pair<int, int> &p(pair<int, int> a) { return P[a.first][a.second]; }
pair<int, int> &pp(pair<int, int> a) { return PP[a.first][a.second]; }
int main() {
  int i, j, k;
  char c;
  int a, d;
  int ts;
  for (ts = 1; scanf("%"
                     "d",
                     &(n)) > 0;
       ++ts) {
    scanf(
        "%"
        "d",
        &(l));
    for (i = (1); i < (n + 1); ++i)
      scanf(
          "%"
          "s",
          &(C[i][1]));
    m = strlen(&C[1][1]);
    for (i = (0); i < (n + 2); ++i) C[i][0] = C[i][m + 1] = '0';
    for (j = (0); j < (m + 2); ++j) C[0][j] = C[n + 1][j] = '0';
    for (i = (1); i < (n + 1); ++i)
      for (j = (1); j < (m + 1); ++j) P[i][j] = PP[i][j] = make_pair(i, j);
    for (i = (1); i < (n + 1); ++i)
      for (j = (1); j < (m + 1); ++j)
        if (C[i][j] != '0')
          for (k = (0); k < (4); ++k) {
            int ii = i + DX[k];
            int jj = j + DY[k];
            if (C[i][j] == C[ii][jj] && color(i, j) != color(ii, jj)) {
              p(color(i, j)) = min(color(i, j), color(ii, jj));
              p(color(ii, jj)) = min(color(i, j), color(ii, jj));
              pp(colorr(i, j)) = max(colorr(i, j), colorr(ii, jj));
              pp(colorr(ii, jj)) = max(colorr(i, j), colorr(ii, jj));
            }
          }
    int kk;
    i = 1;
    j = 1;
    k = 0;
    kk = 0;
    for (; l--;) {
      int x, y;
      if (DX[k] == -1 || (DX[k] != 1 && (k == 0 ^ kk)))
        x = i;
      else
        x = colorr(i, j).first;
      if (DY[k] == -1 || (DY[k] != 1 && (k == 3 ^ kk)))
        y = j;
      else
        y = colorr(i, j).second;
      int ii = x + DX[k];
      int jj = y + DY[k];
      if (C[ii][jj] != '0') {
        pair<int, int> p = color(ii, jj);
        i = p.first;
        j = p.second;
      } else if (kk == 0)
        kk = 1;
      else {
        kk = 0;
        k = (k + 1) % 4;
      }
    }
    printf(
        "%"
        "c",
        (C[i][j]));
    printf("\n"), firstout = 1;
  }
  return 0;
}
