Piet is one of the most known visual esoteric programming languages. The programs in Piet are constructed from colorful blocks of pixels and interpreted using pretty complicated rules. In this problem we will use a subset of Piet language with simplified rules.

The program will be a rectangular image consisting of colored and black pixels. The color of each pixel will be given by an integer number between 0 and 9, inclusive, with 0 denoting black. A block of pixels is defined as a rectangle of pixels of the same color (not black). It is guaranteed that all connected groups of colored pixels of the same color will form rectangular blocks. Groups of black pixels can form arbitrary shapes.

The program is interpreted using movement of instruction pointer (IP) which consists of three parts:

  * current block pointer (BP); note that there is no concept of current pixel within the block;
  * direction pointer (DP) which can point left, right, up or down;
  * block chooser (CP) which can point to the left or to the right from the direction given by DP; in absolute values CP can differ from DP by 90 degrees counterclockwise or clockwise, respectively.



Initially BP points to the block which contains the top-left corner of the program, DP points to the right, and CP points to the left (see the orange square on the image below).

One step of program interpretation changes the state of IP in a following way. The interpreter finds the furthest edge of the current color block in the direction of the DP. From all pixels that form this edge, the interpreter selects the furthest one in the direction of CP. After this, BP attempts to move from this pixel into the next one in the direction of DP. If the next pixel belongs to a colored block, this block becomes the current one, and two other parts of IP stay the same. It the next pixel is black or outside of the program, BP stays the same but two other parts of IP change. If CP was pointing to the left, now it points to the right, and DP stays the same. If CP was pointing to the right, now it points to the left, and DP is rotated 90 degrees clockwise.

This way BP will never point to a black block (it is guaranteed that top-left pixel of the program will not be black).

You are given a Piet program. You have to figure out which block of the program will be current after n steps.

Input

The first line of the input contains two integer numbers m (1 ≤ m ≤ 50) and n (1 ≤ n ≤ 5·107). Next m lines contain the rows of the program. All the lines have the same length between 1 and 50 pixels, and consist of characters 0-9. The first character of the first line will not be equal to 0.

Output

Output the color of the block which will be current after n steps of program interpretation.

Examples

Input

2 10
12
43


Output

1


Input

3 12
1423
6624
6625


Output

6


Input

5 9
10345
23456
34567
45678
56789


Output

5

Note

In the first example IP changes in the following way. After step 1 block 2 becomes current one and stays it after two more steps. After step 4 BP moves to block 3, after step 7 — to block 4, and finally after step 10 BP returns to block 1.

<image>

The sequence of states of IP is shown on the image: the arrows are traversed clockwise, the main arrow shows direction of DP, the side one — the direction of CP.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 262, hm = 52 * 52, maxt = 200;
const long long INF = 1000;
const long double EPS = 1E-9, EPS2 = 1E-8;
const long double M_PIS = 3.14159265358979323846264338327950288;
unsigned char color[hm];
string s[maxn];
pair<int, int> deltas[4];
pair<int, int> pix[hm][4][4];
int used[maxn][maxn], numb = 0, m, p, whose[maxn][maxn], was[hm][4][4];
pair<int, int> cmp(pair<int, int> a, pair<int, int> b, int dp, int cp) {
  if (a.first == -1) return b;
  if (b.first == -1) return a;
  if (dp == 0 && ((a.first < b.first) ||
                  (a.first == b.first && ((a.second < b.second) != cp))))
    return a;
  if (dp == 1 && ((a.second > b.second) ||
                  (a.second == b.second && ((a.first < b.first) != cp))))
    return a;
  if (dp == 2 && ((a.first > b.first) ||
                  (a.first == b.first && ((a.second > b.second) != cp))))
    return a;
  if (dp == 3 && ((a.second < b.second) ||
                  (a.second == b.second && ((a.first > b.first) != cp))))
    return a;
  return b;
}
void dfs(int i, int j, unsigned char c) {
  if (i < 0 || i >= m || j < 0 || j >= p || used[i][j] || s[i][j] != c) return;
  used[i][j] = 1;
  whose[i][j] = numb;
  for (int k = 0; k < 4; ++k)
    for (int l = 0; l < 2; ++l)
      pix[numb][k][l] = cmp(make_pair(i, j), pix[numb][k][l], k, l);
  dfs(i + 1, j, c);
  dfs(i, j + 1, c);
  dfs(i - 1, j, c);
  dfs(i, j - 1, c);
}
pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
void bfs(int id, int dp, int cp, int ost) {
  if (was[id][dp][cp]) {
    ost = (ost % (was[id][dp][cp] - ost));
  }
  was[id][dp][cp] = ost;
  if (ost == 0) {
    cout << color[id] << endl;
    exit(0);
  }
  pair<int, int> px = pix[id][dp][cp] + deltas[dp];
  if (px.first < 0 || px.first >= m || px.second < 0 || px.second >= p ||
      s[px.first][px.second] == '0') {
    if (cp == 0)
      bfs(id, dp, 1, ost - 1);
    else
      bfs(id, (dp + 1) % 4, 0, ost - 1);
  } else
    bfs(whose[px.first][px.second], dp, cp, ost - 1);
}
int main() {
  deltas[0] = make_pair(-1, 0);
  deltas[1] = make_pair(0, 1);
  deltas[2] = make_pair(1, 0);
  deltas[3] = make_pair(0, -1);
  int k, tmp, n;
  cin >> m >> n;
  for (int i = 0; i < m; ++i) cin >> s[i];
  p = s[0].size();
  for (int i = 0; i < m; ++i)
    for (int j = 0; j < s[i].size(); ++j)
      if (!used[i][j] && s[i][j] != '0') {
        color[numb] = s[i][j];
        for (int k = 0; k < 4; ++k)
          for (int l = 0; l < 2; ++l) pix[numb][k][l] = make_pair(-1, 0);
        dfs(i, j, s[i][j]);
        ++numb;
      }
  bfs(0, 1, 0, n);
}
