#include <bits/stdc++.h>
char m[256][256];
int DP = 1;
int CP = -1;
int main() {
  int M, N, W;
  int i;
  int c;
  int nx, ny;
  int x = 1;
  int y = 1;
  memset(m, '0', sizeof(m));
  scanf("%d %d", &M, &N);
  for (i = 1; i <= M; i++) {
    scanf("%s", m[i] + 1);
  }
  W = strlen(m[1] + 1);
  for (i = 1; i <= M; i++) {
    m[i][1 + W] = '0';
  }
  nx = x;
  ny = y;
  for (i = 0; i < N; i++) {
    c = m[y][x];
    if (!DP) {
      while (m[ny - 1][nx] == c) {
        ny--;
      }
      while (m[ny][nx + CP] == c) {
        nx += CP;
      }
      if (m[ny - 1][nx] != '0') {
        ny--;
      } else {
        if (CP < 0) {
          CP = 1;
        } else {
          CP = -1;
          DP = (DP + 1) % 4;
        }
      }
    } else if (DP == 1) {
      while (m[ny][nx + 1] == c) {
        nx++;
      }
      while (m[ny + CP][nx] == c) {
        ny += CP;
      }
      if (m[ny][nx + 1] != '0') {
        nx++;
      } else {
        if (CP < 0) {
          CP = 1;
        } else {
          CP = -1;
          DP = (DP + 1) % 4;
        }
      }
    } else if (DP == 2) {
      while (m[ny + 1][nx] == c) {
        ny++;
      }
      while (m[ny][nx - CP] == c) {
        nx -= CP;
      }
      if (m[ny + 1][nx] != '0') {
        ny++;
      } else {
        if (CP < 0) {
          CP = 1;
        } else {
          CP = -1;
          DP = (DP + 1) % 4;
        }
      }
    } else if (DP == 3) {
      while (m[ny][nx - 1] == c) {
        nx--;
      }
      while (m[ny - CP][nx] == c) {
        ny -= CP;
      }
      if (m[ny][nx - 1] != '0') {
        nx--;
      } else {
        if (CP < 0) {
          CP = 1;
        } else {
          CP = -1;
          DP = (DP + 1) % 4;
        }
      }
    }
    x = nx;
    y = ny;
  }
  printf("%c\n", m[y][x]);
  return 0;
}
