#include <bits/stdc++.h>
using namespace std;

int main(){
int n,k,right=1000000000,left=-1; cin >> n >> k;
int lim = k*k/2 + 1;
bool a;
vector<vector<int>> park(n,vector<int>(n));
vector<vector<int>> s(n+1,vector<int>(n+1));
for(int i=0;i<n;i++){
   for(int j=0;j<n;j++){
      cin >> park.at(i).at(j);
   }
}
while(right - left > 1){
     int mid = (left + right)/2;
     for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
           s.at(i+1).at(j+1) = s.at(i).at(j+1) + s.at(i+1).at(j) - s.at(i).at(j);
           if(park.at(i).at(j) > mid) s.at(i+1).at(j+1)++;
        }
    }
    a = false;
    for(int i=0;i<n-k+1;i++){
       for(int j=0;j<n-k+1;j++){
          if(s.at(i+k).at(j+k) - s.at(i).at(j+k) - s.at(i+k).at(j) + s.at(i).at(j) < lim)a = true;   
       }
    }
if(a) right = mid;
else left = mid;
//cout << left << " " << right <<  endl;
}
cout << right << endl;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
constexpr int inf=1000001000;
constexpr ll INF=2e18;
constexpr ll mod=1000000007;
// ll MOD=998244353;
constexpr ll MOD=998244353;

int main() {
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    vector<map<ll,ll>> dp(n+1);
    dp[0][x]=1;
    rep(i,n) cin >> a[i];
    a.push_back(INF);
    reverse(all(a));
    rep(i,n){
        for (auto it=dp[i].begin();it!=dp[i].end();it++){
            if (it->first>=0){
                dp[i+1][(it->first)%a[i+1]]+=it->second;
                if ((it->first)%a[i+1]!=0 && it->first+a[i+1]<a[i]) dp[i+1][-(a[i+1]-(it->first)%a[i+1])]+=it->second;
            }
            else{
                dp[i+1][-((-it->first)%a[i+1])]+=it->second;
                if ((-it->first)%a[i+1]!=0 && it->first-a[i+1]>-a[i]) dp[i+1][a[i+1]-((-it->first)%a[i+1])]+=it->second;
            }
        }
    }
    cout << dp[n][0] << endl;
}
