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
#include <cstdio>

using namespace std;


const int MAX = 2005;
int takeOut[MAX][MAX];

void findTakeOuts() {
    takeOut[1][1] = 1;
    takeOut[2][1] = 2;
    takeOut[2][2] = 2;
    for (int i = 3; i < MAX; i++) {
        takeOut[i][1] = takeOut[i-1][1] + 1;
        for (int j = 2; j <= i; j++) {
            takeOut[i][j] = takeOut[i-1][j-1] + takeOut[i-1][j] + 1 - takeOut[i-2][j-1];
        }
    }
}

int main() {
    findTakeOuts();
    int n, k;

    while (scanf("%d %d", &n, &k) > 0) {
        int year = 2020;
        int currentYear = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                scanf("%d", &currentYear);
                if (takeOut[i][j] <= k && currentYear < year) {
                    year = currentYear;
                }
            }
        }
        printf("%d\n", year);
    }
}