// Problem: D - KAIBUNsyo
// Contest: AtCoder - AtCoder Beginner Contest 206（Sponsored by Panasonic）
// URL: https://atcoder.jp/contests/abc206/tasks/abc206_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

// krishrawat

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define pb insert
#define eb emplace_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define show(x) cerr << #x << " is " << x << "\n"
#define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n"
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> pp;
typedef vector<pp> vp;
typedef map<ll, ll> ii;
typedef set<ll> sl;
typedef multiset<ll> msl;
typedef set<pair<ll, ll>> sp;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 1;
ll mod_mul(ll x, ll y) { return ((x % MOD) * (y % MOD)) % MOD; }
ll mod_add(ll x, ll y) { return ((x % MOD) + (y % MOD)) % MOD; }

ll par[N];
ll sz[N];

ll find_par(ll x) {
  if (par[x] == x) return x;
  return par[x] = find_par(par[x]);
}

void join(ll x, ll y) {
  x = find_par(x);
  y = find_par(y);
  if (x != y) {
    if (sz[y] > sz[x]) swap(x, y);
    sz[x] += sz[y];
    par[y] = x;
  }
}

// main code
void solve() {
  ll n;
  cin >> n;
  vl v(n);
  for (auto &i : v) {
    cin >> i;
    par[i] = i;
    sz[i] = 1;
  }
  ll i = 0, j = n - 1;
  ll ans = 0;
  while (i < j) {
    ll a = v[i];
    ll b = v[j];
    a = find_par(a);
    b = find_par(b);
    if (a != b) {
      ans++;
      join(a, b);
    }
    i++;
    j--;
  }
  cout << ans << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll t;
  t = 1;
  // cin >> t;
  while (t--) solve();
  return 0;
}

#include <bits/stdc++.h>
#define int long long
#define f(i,a,n) for (int i = a; i < n; ++i)
#define fr(i,a,n) for(int i=a;i>=n;i--)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL);
#define w1 solve();
#define MOD (int)(1e9 + 7)
#define prq priority_queue
#define gcd __gcd
#define sz(x) (int)x.size()
#define w(t) int t; cin>>t; f(i,1,t+1) {solve(i);}

using namespace std;


#ifdef Avash_Local_Machine
#include "debug.h"
#else
#define debug(x...)
#endif


typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;


const int INF = (int)(1e17);
const double PI = 3.141592653589793;

int dx[4] = { -1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
string path = "URDL";

// #define SIZE (int)(10000)
// vector<int> adj[SIZE];
// vector<pii> adj[SIZE];
// vector<int> vis(SIZE, 0);

int dp[801][801];
int arr[801][801];

void solve(int tc = 1) {
	int n, k;
	cin >> n >> k;
	f(i, 0, n) f(j, 0, n) cin >> arr[i][j];

	int l = 0, r = 1e9;
	int ans = -1;
	while (l <= r)
	{
		int mid = (l + r) / 2;
		f(i, 0, n) f(j, 0, n) {
			if (arr[i][j] <= mid) dp[i][j] = 1;
			else dp[i][j] = 0;
		}

		f(i, 0, n) f(j, 0, n)
		{
			if (i > 0) dp[i][j] += dp[i - 1][j];
			if (j > 0) dp[i][j] += dp[i][j - 1];
			if (i > 0 and j > 0) dp[i][j] -= dp[i - 1][j - 1];


		}

		bool ok = false;

		f(i, k - 1, n)
		{
			f(j, k - 1, n)
			{
				int sum = dp[i][j];
				if (i >= k)sum -= dp[i - k][j];
				if (j >= k)sum -= dp[i][j - k];
				if (i >= k and j >= k)sum += dp[i - k][j - k];

				int x = (k * k) / 2;
				if (k & 1) x++;

				if (sum >= x) {
					ok = true;
					break;
				}

			}

			if (ok == true) break;
		}

		if (ok)
		{
			r = mid - 1;
			ans = mid;
		}
		else l = mid + 1;
	}

	cout << ans << "\n";
}

int32_t main()
{

	fastio
	clock_t begin = clock();
	w1

	clock_t end = clock();
#ifdef Avash_Local_Machine

	cerr << "Executed In: " << double(end - begin) / CLOCKS_PER_SEC * 1000 << " ms\n";
#endif

	return 0;
}