Forest

No attempts yetTime limit1sMemory limit128 MB

Problem

Mr. Jan owns a large forest that covers a square plot with side length nn. The trees are planted on a grid, with nn trees in every row and nn trees in every column, for a total of n2n^2 trees. Each tree has a fixed age.

Mr. Jan wants to build a house of area dd. To do that he must clear part of the forest, and since each tree occupies exactly 11 unit of area, he must cut down exactly dd trees. The cleared trees have to form a single connected region, where two trees are adjacent only when they share an edge (up, down, left, or right); touching only at a corner does not count as connected.

Mr. Jan wants the oldest tree among all the ones he cuts down to be as young as possible. Find that minimum possible value.

Input

The first line contains two integers nn and dd separated by a space (1n10001 \le n \le 1\,000, 1dn21 \le d \le n^2): the side length of the forest and the area of the house Mr. Jan wants to build.

Each of the next nn lines contains nn integers w(i,k)w(i, k) (1w(i,k)1091 \le w(i, k) \le 10^9), the age of the tree in the ii-th row from the top and the kk-th column from the left.

Output

Print a single integer: over every valid connected region of exactly dd trees, the smallest possible age of the oldest tree in the region that is cut down.