#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
template <class T>
T MIN(const T& a, const T& b) {
  return a < b ? a : b;
}
template <class T>
T MAX(const T& a, const T& b) {
  return a > b ? a : b;
}
template <class T>
void MIN_UPDATE(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void MAX_UPDATE(T& a, const T& b) {
  if (a < b) a = b;
}
enum { EAST, SOUTH, WEST, NORTH };
const char* DIRECTION_STRINGS[] = {
    "EAST",
    "SOUTH",
    "WEST",
    "NORTH",
};
const int DR[] = {0, 1, 0, -1};
const int DC[] = {1, 0, -1, 0};
bool in(int r, int c, int R, int C) {
  return 0 <= r && r < R && 0 <= c && c < C;
}
int main() {
  std::ios::sync_with_stdio(false);
  int M, N;
  cin >> M >> N;
  vector<string> maze;
  for (int r = 0; r < (int)M; ++r) {
    string in;
    cin >> in;
    maze.push_back(in);
  }
  int R = maze.size();
  int C = maze[0].size();
  static char table[64][64];
  for (int r = 0; r < (int)R; ++r) {
    for (int c = 0; c < (int)C; ++c) {
      table[r][c] = maze[r][c];
    }
  }
  static pair<int, int> furthest[64][64][4];
  for (int startR = 0; startR < (int)R; ++startR) {
    for (int startC = 0; startC < (int)C; ++startC) {
      if (table[startR][startC] == '0') {
        continue;
      }
      for (int dir = 0; dir < (int)4; ++dir) {
        pair<int, int> current = make_pair((startR), (startC));
        for (;;) {
          pair<int, int> next = current;
          next.first += DR[dir];
          next.second += DC[dir];
          if (!in(next.first, next.second, R, C)) {
            break;
          }
          if (table[current.first][current.second] !=
              table[next.first][next.second]) {
            break;
          }
          current = next;
        }
        furthest[startR][startC][dir] = current;
      }
    }
  }
  pair<int, int> bp;
  int dp = EAST;
  int cp = NORTH;
  for (int n = 0; n < (int)N; ++n) {
    pair<int, int> furthestDp = furthest[bp.first][bp.second][dp];
    pair<int, int> furthestCp =
        furthest[furthestDp.first][furthestDp.second][cp];
    pair<int, int> nextPixel = furthestCp;
    nextPixel.first += DR[dp];
    nextPixel.second += DC[dp];
    if (in(nextPixel.first, nextPixel.second, R, C) &&
        table[nextPixel.first][nextPixel.second] != '0') {
      bp = nextPixel;
      continue;
    }
    if (cp == (dp + 3) % 4) {
      cp = (dp + 1) % 4;
      continue;
    }
    dp = (dp + 1) % 4;
    cp = (dp + 3) % 4;
  }
  cout << table[bp.first][bp.second] << endl;
}
