#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000")
using namespace std;
long long labs(long long a) { return a < 0 ? (-a) : a; }
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
const int MAXN = 55;
char mas[MAXN][MAXN];
int mask[MAXN][MAXN];
int n, m, k;
void Input() {
  cin >> n >> k;
  fill(&mas[0][0], &mas[0][0] + MAXN * MAXN, '0');
  string s;
  for (int(i) = 1; (i) < (n + 1); (i)++) {
    cin >> s;
    m = s.size();
    for (int(j) = 0; (j) < (m); (j)++) {
      mas[i][j + 1] = s[j];
    }
  }
  n++;
  m++;
}
struct Block {
  char color;
  pair<int, int> p1, p2;
  vector<int> to;
  Block() { to.assign(8, 0); }
  void Calc() {
    to[0] = mask[p1.first][p2.second + 1];
    to[1] = mask[p2.first][p2.second + 1];
    to[2] = mask[p2.first + 1][p2.second];
    to[3] = mask[p2.first + 1][p1.second];
    to[4] = mask[p2.first][p1.second - 1];
    to[5] = mask[p1.first][p1.second - 1];
    to[6] = mask[p1.first - 1][p1.second];
    to[7] = mask[p1.first - 1][p2.second];
  }
};
vector<Block> v;
void FindBlocks() {
  memset((mask), 0, sizeof(mask));
  int color = 1;
  v.push_back(Block());
  for (int(i) = 0; (i) < (n); (i)++) {
    for (int(j) = 0; (j) < (m); (j)++) {
      if (!mask[i][j] && mas[i][j] != '0') {
        Block b;
        b.color = mas[i][j];
        b.p1 = make_pair(i, j);
        b.p2 = b.p1;
        for (int q = i; mas[q][j] == mas[i][j]; q++) {
          for (int p = j; mas[q][p] == mas[i][j]; p++) {
            mask[q][p] = color;
            b.p2.second = max(b.p2.second, p);
          }
          b.p2.first = q;
        }
        v.push_back(b);
        color++;
      }
    }
  }
  for (int(i) = 1; (i) < (v.size()); (i)++) {
    v[i].Calc();
  }
}
int main() {
  Input();
  FindBlocks();
  int cur = 1;
  int dir = 0;
  for (int(i) = 0; (i) < (k); (i)++) {
    if (v[cur].to[dir] == 0) {
      dir = (dir + 1) % 8;
    } else {
      cur = v[cur].to[dir];
    }
  }
  cout << v[cur].color << endl;
  return 0;
}
