#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-18;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
const int MAX_N = 64;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
const int ccp[] = {1, -1};
int n, m, pc;
char s[MAX_N][MAX_N];
int pr[MAX_N][MAX_N][4][2];
pair<int, int> memo[MAX_N][MAX_N][4];
pair<int, int> nex(int y, int x, int d) {
  if (memo[y][x][d].first != -1) return memo[y][x][d];
  int ny = y, nx = x;
  while (s[y][x] == s[y + dy[d]][x + dx[d]]) {
    y += dy[d];
    x += dx[d];
  }
  return memo[ny][nx][d] = pair<int, int>(y, x);
}
int main() {
  for (long long int i = (0); i < (long long int)(MAX_N); i++)
    for (long long int j = (0); j < (long long int)(MAX_N); j++)
      for (long long int k = (0); k < (long long int)(4); k++)
        memo[i][j][k] = pair<int, int>(-1, -1);
  for (long long int i = (0); i < (long long int)(MAX_N); i++)
    for (long long int j = (0); j < (long long int)(MAX_N); j++)
      for (long long int k = (0); k < (long long int)(4); k++)
        for (long long int l = (0); l < (long long int)(2); l++)
          pr[i][j][k][l] = -1;
  scanf("%d %d", &n, &pc);
  for (long long int i = (0); i < (long long int)(n); i++)
    scanf("%s", s[i + 1] + 1);
  m = strlen(s[1] + 1);
  for (long long int i = (0); i < (long long int)(n + 2); i++)
    s[i][0] = s[i][m + 1] = '0';
  for (long long int j = (0); j < (long long int)(m + 2); j++)
    s[0][j] = s[n + 1][j] = '0';
  int y = 1, x = 1, dp = 0, cp = 0;
  while (pc--) {
    if (pr[y][x][dp][cp] != -1) m %= pr[y][x][dp][cp] - pc;
    pr[y][x][dp][cp] = pc;
    auto ne = nex(y, x, dp);
    ne = nex(ne.first, ne.second, (dp + ccp[cp] + 4) % 4);
    ne = pair<int, int>(ne.first + dy[dp], ne.second + dx[dp]);
    if (s[ne.first][ne.second] == '0') {
      if (cp == 0)
        cp = 1;
      else
        cp = 0, dp = (dp + 3) % 4;
    } else {
      y = ne.first;
      x = ne.second;
    }
  }
  printf("%c\n", s[y][x]);
  return 0;
}
