#include <bits/stdc++.h>
using namespace std;
int n, k, m;
int a[100][100];
string s;
pair<int, int> up_right[100][100], up_left[100][100], down_right[100][100],
    down_left[100][100];
int x, y, xx, yy;
int cp, dp;
int main() {
  scanf("%d %d\n", &n, &k);
  for (int i = 0; i < n; i++) {
    getline(cin, s);
    m = s.size();
    for (int j = 0; j < s.size(); j++) a[i][j] = s[j] - '0';
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      x = i;
      y = j;
      while (x >= 0 && a[x][y] == a[i][j]) x--;
      x++;
      while (y >= 0 && a[x][y] == a[i][j]) y--;
      y++;
      up_left[i][j] = make_pair(x, y);
      x = i;
      y = j;
      while (x >= 0 && a[x][y] == a[i][j]) x--;
      x++;
      while (y < m && a[x][y] == a[i][j]) y++;
      y--;
      up_right[i][j] = make_pair(x, y);
      x = i;
      y = j;
      while (x < n && a[x][y] == a[i][j]) x++;
      x--;
      while (y < m && a[x][y] == a[i][j]) y++;
      y--;
      down_right[i][j] = make_pair(x, y);
      x = i;
      y = j;
      while (x < n && a[x][y] == a[i][j]) x++;
      x--;
      while (y >= 0 && a[x][y] == a[i][j]) y--;
      y++;
      down_left[i][j] = make_pair(x, y);
    }
  x = 0;
  y = 0;
  dp = 1;
  cp = 4;
  for (int t = 1; t <= k; t++) {
    if (dp == 1) {
      if (cp == 4) {
        xx = up_right[x][y].first;
        yy = up_right[x][y].second;
      } else {
        xx = down_right[x][y].first;
        yy = down_right[x][y].second;
      }
    } else if (dp == 2) {
      if (cp == 1) {
        xx = down_right[x][y].first;
        yy = down_right[x][y].second;
      } else {
        xx = down_left[x][y].first;
        yy = down_left[x][y].second;
      }
    } else if (dp == 3) {
      if (cp == 4) {
        xx = up_left[x][y].first;
        yy = up_left[x][y].second;
      } else {
        xx = down_left[x][y].first;
        yy = down_left[x][y].second;
      }
    } else if (dp == 4) {
      if (cp == 1) {
        xx = up_right[x][y].first;
        yy = up_right[x][y].second;
      } else {
        xx = up_left[x][y].first;
        yy = up_left[x][y].second;
      }
    }
    x = xx;
    y = yy;
    if (dp == 1) {
      if (y + 1 >= m || a[x][y + 1] == 0) {
        if (cp == 4)
          cp = 2;
        else {
          dp = 2;
          cp = 1;
        }
      } else
        y = y + 1;
    } else if (dp == 2) {
      if (x + 1 >= n || a[x + 1][y] == 0) {
        if (cp == 1)
          cp = 3;
        else {
          dp = 3;
          cp = 2;
        }
      } else
        x = x + 1;
    } else if (dp == 3) {
      if (y - 1 < 0 || a[x][y - 1] == 0) {
        if (cp == 2)
          cp = 4;
        else {
          dp = 4;
          cp = 3;
        }
      } else
        y = y - 1;
    } else {
      if (x - 1 < 0 || a[x - 1][y] == 0) {
        if (cp == 3)
          cp = 1;
        else {
          dp = 1;
          cp = 4;
        }
      } else
        x = x - 1;
    }
  }
  cout << a[x][y];
  return 0;
}
