#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rrep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fore(i,a) for(auto &i:a)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll n, k;
ll a[805][805];

bool check(ll lim){
    ll thanlim[805][805];
    ll median = k*k/2+1;
    rep(i,0,n){
        rep(j,0,n){
            if(a[i][j] >= lim) thanlim[i][j] = 1;
            else thanlim[i][j] = 0;
        }
    }
    vector<vector<int> > s(n+1, vector<int>(n+1, 0));
    rep(i,0,n){
        rep(j,0,n){
            s[i+1][j+1]=s[i][j+1]+s[i+1][j]-s[i][j]+thanlim[i][j];
        }
    }
    bool all_thanlim = true;
    rep(i,0,n-k+1){
        rep(j,0,n-k+1){
            ll cnt = s[i+k][j+k]+s[i][j]-s[i+k][j]-s[i][j+k];
            if(cnt < median) all_thanlim = false;
        }    
    }
    return all_thanlim;
}

int main(){
    cin >> n >> k;
    rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];
    ll inf = 1000000001;
    ll ok = 0, ng = inf;
    while (ok + 1 != ng) {
        int md = (ok + ng) / 2;
        if (check(md)) ok = md;
        else ng = md;
    }
    printf("%lld\n", ok);
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,K=0,P=0,i=1;cin>>N>>M;
  int A[M+2],B[M+1];
  A[0]=0;
  for(;i<=M;i++)cin>>A[i];
  A[M+1]=N+1;
  sort(A,A+M+2);
  for(i=0;i<M+1;i++)B[i]=A[i+1]-A[i]-1;
  sort(B,B+M+1);
  for(i=0;i<M+1;i++){
    if(!K)K=B[i];
    if(K)P+=(B[i]+K-1)/K;
  }
  cout<<P;
}