//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 105
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
#define pii pair <ll, ll>
#define fi first
#define se second
using namespace std;
typedef long long ll;

const ll INF = 1e13;
ll N, X, a[MAX], ans, rnd, M;
ll vis[MAX][MAX][MAX];
ll memo[MAX][MAX][MAX];
 
ll dp(ll i, ll k, ll md) {
    if(i > N) {
        if(md or k)
            return -INF;
        return 0;
    }
    if(vis[i][k][md] == rnd)
        return memo[i][k][md];

    // NOPE
    ll ans = dp(i + 1, k, md);
    // YEP
    if(k > 0)
        ans = max(ans, dp(i + 1, k - 1, (md + a[i]) % M) + a[i]);
    vis[i][k][md] = rnd;
    return memo[i][k][md] = ans;
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif
    optimiza_io
    cin >> N >> X;
    for(ll i = 1; i <= N; i ++)
        cin >> a[i];
    sort(a + 1, a + N + 1);
    ans = X - a[N];

    for(ll i = 2; i <= N; i ++) {
        rnd++;
        M = i;
        ll st = (i - (X % i)) % i;
        ll can = dp(1, i, st);
        if(can > 0)
            ans = min(ans, (X - can) / i);
    }


    cout << ans << "\n";
    return 0;
}
 
// CHECAR LIMITES 
#include <bits/stdc++.h>
using namespace std;
 
void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
 
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
 
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
 
#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

int main() {
	int n, k;
	cin >> n >> k;

	vector<vector<int>> a(n, vector<int>(n));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++)
			cin >> a[i][j];
	}

	int w = (k*k + 1) / 2;

	auto can = [&] (int x) {
		auto b = a;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(b[i][j] <= x)
					b[i][j] = 1;
				else
					b[i][j] = 0;
			}
		}

		// is there a k x k submatrix of b with sum >= w?

		vector<vector<int>> pref(n + 1, vector<int>(n + 1));
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				pref[i + 1][j] = pref[i][j] + b[i][j]; 
			}
		}

		for(int i = 0; i < n + 1 - k; i++) {
			int sum = 0;
			for(int a = 0; a < k; a++) {
				sum += pref[i + k][a] - pref[i][a]; 
			}

			debug(i + 1, x, sum);
			for(int j = 0; j < n + 1 - k; j++) {
				debug(x, i + 1, j + 1, sum);
				if(sum >= w) {
					debug(x, i + 1, j + 1, sum);
					return true; 
				}
				if(j + k < n) {
					sum -= pref[i + k][j] - pref[i][j];
					sum += pref[i + k][j + k] - pref[i][j + k];
				}
			}
		}

		return false;
	};


	debug(can(4));

	int lo = 0, hi = 1E9 + 5;

	 while(lo < hi) {
	 	int mid = (lo + hi) / 2;
	 	if(can(mid))
	 		hi = mid;
	 	else
	 		lo = mid + 1;
	 }

	 assert(can(lo));

	 cout << lo << '\n';
}