#include <bits/stdc++.h>
using namespace std;
struct node {
  int x0, y0, x1, y1;
} b[2505];
int vis[55][55], n, m, k;
char s[55][55];
int check(int x, int y) {
  if (x >= 0 && x < n && y >= 0 && y < m) return 1;
  return 0;
}
int main() {
  scanf("%d%d", &n, &k);
  int cnt = 0;
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  m = strlen(s[0]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (!vis[i][j] && s[i][j] != '0') {
        cnt++;
        int k;
        for (k = i; s[k][j] == s[i][j]; k++)
          ;
        int x = k;
        for (k = j; s[i][k] == s[i][j]; k++)
          ;
        int y = k;
        for (int k = i; k < x; k++)
          for (int l = j; l < y; l++) vis[k][l] = cnt;
        b[cnt].x0 = i;
        b[cnt].y0 = j;
        b[cnt].x1 = x - 1;
        b[cnt].y1 = y - 1;
      }
    }
  int bp = 1, dp = 0, cp = 0;
  while (k--) {
    int x0 = b[bp].x0;
    int x1 = b[bp].x1;
    int y1 = b[bp].y1;
    int y0 = b[bp].y0;
    if (dp == 0) {
      if (cp == 0)
        if (check(x0, y1 + 1) && s[x0][y1 + 1] != '0') {
          bp = vis[x0][y1 + 1];
        } else {
          cp = 1;
        }
      else if (check(x1, y1 + 1) && s[x1][y1 + 1] != '0') {
        bp = vis[x1][y1 + 1];
      } else {
        cp = 0;
        dp = 1;
      }
    } else if (dp == 1) {
      if (cp == 0)
        if (check(x1 + 1, y1) && s[x1 + 1][y1] != '0') {
          bp = vis[x1 + 1][y1];
        } else {
          cp = 1;
        }
      else if (check(x1 + 1, y0) && s[x1 + 1][y0] != '0') {
        bp = vis[x1 + 1][y0];
      } else {
        cp = 0;
        dp = 2;
      }
    } else if (dp == 2) {
      if (cp == 0)
        if (check(x1, y0 - 1) && s[x1][y0 - 1] != '0') {
          bp = vis[x1][y0 - 1];
        } else {
          cp = 1;
        }
      else if (check(x0, y0 - 1) && s[x0][y0 - 1] != '0') {
        bp = vis[x0][y0 - 1];
      } else {
        cp = 0;
        dp = 3;
      }
    } else if (dp == 3) {
      if (cp == 0)
        if (check(x0 - 1, y0) && s[x0 - 1][y0] != '0') {
          bp = vis[x0 - 1][y0];
        } else {
          cp = 1;
        }
      else if (check(x0 - 1, y1) && s[x0 - 1][y1] != '0') {
        bp = vis[x0 - 1][y1];
      } else {
        cp = 0;
        dp = 0;
      }
    }
  }
  printf("%c\n", s[b[bp].x0][b[bp].y0]);
}
