#include <bits/stdc++.h>
using namespace std;
struct str {
  int i1, j1, i2, j2;
  str(int _i1 = -1, int _j1 = -1, int _i2 = -1, int _j2 = -1)
      : i1(_i1), j1(_j1), i2(_i2), j2(_j2){};
};
int main() {
  int n, k;
  cin >> n >> k;
  vector<string> s(n);
  for (int i = 0; i < int((s).size()); ++i) cin >> s[i];
  int m = s[0].size();
  vector<vector<vector<vector<str> > > > a(n);
  for (int i = 0; i < int((a).size()); ++i) a[i].resize(m);
  for (int i = 0; i < int((a).size()); ++i)
    for (int j = 0; j < int(((a)[i]).size()); ++j) a[i][j].resize(4);
  for (int i = 0; i < int((a).size()); ++i)
    for (int j = 0; j < int(((a)[i]).size()); ++j)
      for (int t = 0; t < int((a[i][j]).size()); ++t) a[i][j][t].resize(2);
  for (int i1 = 0; i1 < int((a).size()); ++i1)
    for (int j1 = 0; j1 < int(((a)[i1]).size()); ++j1)
      for (int i2 = 0; i2 < int((a[i1][j1]).size()); ++i2)
        for (int j2 = 0; j2 < int(((a[i1][j1])[i2]).size()); ++j2) {
          int x = i1, y = j1;
          switch (i2) {
            case 0:
              while (y + 1 < m && s[x][y + 1] == s[i1][j1]) ++y;
              break;
            case 1:
              while (x > 0 && s[x - 1][y] == s[i1][j1]) --x;
              break;
            case 2:
              while (y > 0 && s[x][y - 1] == s[i1][j1]) --y;
              break;
            case 3:
              while (x + 1 < n && s[x + 1][y] == s[i1][j1]) ++x;
              break;
          }
          if (j2 == 0) switch (i2) {
              case 3:
                while (y + 1 < m && s[x][y + 1] == s[i1][j1]) ++y;
                break;
              case 0:
                while (x > 0 && s[x - 1][y] == s[i1][j1]) --x;
                break;
              case 1:
                while (y > 0 && s[x][y - 1] == s[i1][j1]) --y;
                break;
              case 2:
                while (x + 1 < n && s[x + 1][y] == s[i1][j1]) ++x;
                break;
            }
          else
            switch (i2) {
              case 1:
                while (y + 1 < m && s[x][y + 1] == s[i1][j1]) ++y;
                break;
              case 2:
                while (x > 0 && s[x - 1][y] == s[i1][j1]) --x;
                break;
              case 3:
                while (y > 0 && s[x][y - 1] == s[i1][j1]) --y;
                break;
              case 0:
                while (x + 1 < n && s[x + 1][y] == s[i1][j1]) ++x;
                break;
            }
          int nx = x, ny = y;
          switch (i2) {
            case 0:
              ++ny;
              break;
            case 1:
              --nx;
              break;
            case 2:
              --ny;
              break;
            case 3:
              ++nx;
              break;
          }
          if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] != '0') {
            a[i1][j1][i2][j2] = str(nx, ny, i2, j2);
          } else {
            if (j2 == 0)
              a[i1][j1][i2][j2] = str(i1, j1, i2, 1);
            else
              a[i1][j1][i2][j2] = str(i1, j1, (i2 - 1 + 4) % 4, 0);
          }
        }
  str cur = str(0, 0, 0, 0);
  for (int i = 0; i < k; ++i) cur = a[cur.i1][cur.j1][cur.i2][cur.j2];
  cout << s[cur.i1][cur.j1] << endl;
  return 0;
}
