1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <cstdio>
#include <deque>
using namespace std;
int n, k, res = 2020;
deque <int> arr, arr_input;
void input (deque <int> &arr_input, int size) {
  int x;
  for (int i = 0; i < size; i++) {
    scanf ("%d", &x);
    arr_input.push_back(x);
  }
}
void mmm(deque <int> &arr, int &q, int w, int f) {
  for (int i = 0; i < w; i++) {
    arr.push_back(arr.front() + q);
    arr.pop_front();
    q += f;
  }
}
void new_level(deque <int> &arr) {
  int q = 1, w = arr.size() / 2;
  if (arr.size() % 2 == 1) {
    mmm(arr, q, w + 1, 1);
    arr.push_back(arr.back());
    q -= 2;
    mmm(arr, q, w, -1);
  }
  else {
    mmm(arr, q, w, 1);
    arr.push_back(arr.back() + 1);
    q--;
    mmm(arr, q, w, -1);
  }
}

void solve(deque <int> &arr_input, deque <int> &arr, int &res, int &k) {
  for (int i = arr_input.size() - 1; i >= 0; i--) {
    if (arr[i] <= k) {
      res = min(res, arr_input.back());
    }
    arr_input.pop_back();
  }
}
int main() {
  arr.push_back(1);
  scanf ("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    input(arr_input, i);
    if (i > 1) {
      new_level(arr);
    }
    solve (arr_input, arr, res, k);
  }
  printf ("%d\n", res);

  return 0;
}