// Atcoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES

#include<math.h>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
#include <sstream>



using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
//#define LINF (1e18)
#define MOD (1e9+7)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,N)for(int i =1;i<=N;++i)
#define all(x) (x).begin(),(x).end()
//#define int long long
const int INF = 1e9;
const ll LINF = 1e18;
//typedef pair < ll, ll> P;

//元がintの分けたものを返す p[0]は1桁目
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
//桁数を返す
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
//元がstringの分けたものを返す d[0]は一桁目
vector<int> convertstring(string s) {
	vector<int> d;
	ll n = s.size();
	reverse(s.begin(), s.end());
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}

/*long double　は%Lf*/
//queue古い順,stack新しい
//bool operator<(const Info &another) const {return x > another.x;}//struct(構造体)内の比較演算子のオバーロード
int N,K;
int A[805][805];
ll Dcnt[805][805];
void CSum2D(int H,int W) {
	rep(i, H)rep(j, W) {
		if (i > 0)Dcnt[i][j] += Dcnt[i - 1][j];
		if (j > 0)Dcnt[i][j] += Dcnt[i][j - 1];
		if (i > 0 && j > 0)Dcnt[i][j] -= Dcnt[i - 1][j - 1];
	}
}
int32_t main() {
	cin >> N >> K;
	rep(i, N)rep(j, N)cin >> A[i][j];
	int ul = INF, bl = -1;
	while (ul - bl > 1) {
		int mid = (ul + bl) >> 1;
		rep(i, N) {
			rep(j, N) {
				if (A[i][j] <= mid)Dcnt[i][j] = 1;
				else Dcnt[i][j] = 0;
			}
		}
		CSum2D(N, N);
		int thres = K*K-K * K / 2;
		rep(i, N)rep(j, N) {
			if (i + K - 1 >= N || j + K - 1 >= N)continue;
			ll sum = Dcnt[i + K - 1][j + K - 1];
			if (i > 0)sum -= Dcnt[i - 1][j+K-1];
			if (j > 0)sum -= Dcnt[i+K-1][j - 1];
			if (i > 0 && j > 0)sum += Dcnt[i - 1][j - 1];
			if (sum >= thres) {
				ul = mid;
				break;
				
			}
		}
		if(ul!=mid)bl = mid;

	}
	cout << ul << endl;

}

/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    char ch, ch2;
    cin >> ch >> ch2;
    if (ch == 'Y') cout << char(ch2 - 32);
    else cout << ch2;
    return 0;
}
