#include <bits/stdc++.h>
using namespace std;
const char UP = '1';
const char DOWN = '2';
const char LEFT = '3';
const char RIGHT = '4';
const int MAX_N = 55;
string a[MAX_N];
int bp_x, bp_y, bp_new_x, bp_new_y, m, n;
char dp, cp;
void way(char x) {
  bp_new_x = bp_x;
  bp_new_y = bp_y;
  char w = a[bp_x][bp_y];
  if (x == RIGHT) {
    string s = a[bp_x];
    while ((bp_new_y < (int)s.length()) && (a[bp_new_x][bp_new_y] == w))
      bp_new_y++;
    bp_new_y--;
  } else if (x == LEFT) {
    while ((bp_new_y >= 0) && (a[bp_new_x][bp_new_y] == w)) bp_new_y--;
    bp_new_y++;
  } else if (x == UP) {
    while ((bp_new_x >= 0) && (a[bp_new_x][bp_new_y] == w)) bp_new_x--;
    bp_new_x++;
  } else {
    while ((bp_new_x < m) && (a[bp_new_x][bp_new_y] == w)) bp_new_x++;
    bp_new_x--;
  }
  bp_x = bp_new_x;
  bp_y = bp_new_y;
}
void change_way() {
  if ((dp == RIGHT) && (cp == UP))
    cp = DOWN;
  else if ((dp == DOWN) && (cp == RIGHT))
    cp = LEFT;
  else if ((dp == LEFT) && (cp == DOWN))
    cp = UP;
  else if ((dp == UP) && (cp == LEFT))
    cp = RIGHT;
  else if ((dp == RIGHT) && (cp == DOWN)) {
    dp = DOWN;
    cp = RIGHT;
  } else if ((dp == DOWN) && (cp == LEFT)) {
    dp = LEFT;
    cp = DOWN;
  } else if ((dp == LEFT) && (cp == UP)) {
    dp = UP;
    cp = LEFT;
  } else if ((dp == UP) && (cp == RIGHT)) {
    dp = RIGHT;
    cp = UP;
  }
  return;
}
int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  cin >> m >> n;
  for (int i = 0; i < m; i++) cin >> a[i];
  bp_x = 0;
  bp_y = 0;
  bp_new_x = 0;
  bp_new_y = 0;
  dp = RIGHT;
  cp = UP;
  for (int i = 0; i < n; i++) {
    way(dp);
    way(cp);
    if (dp == RIGHT) {
      string s = a[bp_x];
      if ((bp_y == (int)s.length() - 1) || (a[bp_x][bp_y + 1] == '0'))
        change_way();
      else
        bp_y++;
    } else if (dp == LEFT) {
      if ((bp_y == 0) || (a[bp_x][bp_y - 1] == '0'))
        change_way();
      else
        bp_y--;
    } else if (dp == UP) {
      if ((bp_x == 0) || (a[bp_x - 1][bp_y] == '0'))
        change_way();
      else
        bp_x--;
    } else {
      if ((bp_x == m - 1) || (a[bp_x + 1][bp_y] == '0'))
        change_way();
      else
        bp_x++;
    }
  }
  cout << a[bp_x][bp_y];
  return 0;
}
