#include <bits/stdc++.h>
using namespace std;
const int maxn = 101;
int n, m, step, p[maxn][maxn], l[maxn][maxn], r[maxn][maxn], d[maxn][maxn],
    u[maxn][maxn];
bool ss[maxn][maxn];
string s[maxn];
int main() {
  cin >> n >> step;
  for (int i = 0; i < n; i++) cin >> s[i];
  m = s[0].length();
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (!ss[i][j]) {
        int x = i, y = j;
        while (x < n && s[x][j] == s[i][j]) x++;
        while (y < m && s[i][y] == s[i][j]) y++;
        x--;
        y--;
        for (int a = i; a <= x; a++)
          for (int b = j; b <= y; b++) {
            ss[a][b] = true;
            l[a][b] = j;
            r[a][b] = y;
            u[a][b] = i;
            d[a][b] = x;
          }
      }
  int bpx = 0, bpy = 0, dp = 1, cp = 0;
  for (; step; step--) {
    if (dp == 0) {
      int x = u[bpx][bpy] - 1, y = cp == 0 ? l[bpx][bpy] : r[bpx][bpy];
      if (x < 0 || s[x][y] == '0') {
        if (cp == 0)
          cp = 1;
        else
          dp = (dp + 1) % 4, cp = 0;
      } else
        bpx = x, bpy = y;
    } else if (dp == 1) {
      int x = cp == 0 ? u[bpx][bpy] : d[bpx][bpy], y = r[bpx][bpy] + 1;
      if (y >= m || s[x][y] == '0') {
        if (cp == 0)
          cp = 1;
        else
          dp = (dp + 1) % 4, cp = 0;
      } else
        bpx = x, bpy = y;
    } else if (dp == 2) {
      int x = d[bpx][bpy] + 1, y = cp == 1 ? l[bpx][bpy] : r[bpx][bpy];
      if (x >= n || s[x][y] == '0') {
        if (cp == 0)
          cp = 1;
        else
          dp = (dp + 1) % 4, cp = 0;
      } else
        bpx = x, bpy = y;
    } else if (dp == 3) {
      int x = cp == 1 ? u[bpx][bpy] : d[bpx][bpy], y = l[bpx][bpy] - 1;
      if (y < 0 || s[x][y] == '0') {
        if (cp == 0)
          cp = 1;
        else
          dp = (dp + 1) % 4, cp = 0;
      } else
        bpx = x, bpy = y;
    }
  }
  cout << s[bpx][bpy] << endl;
}
