#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
constexpr ll MOD = 998244353;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
ostream &operator<<(ostream &o, const string &obj) {o << "\""; o << obj.c_str(); o << "\""; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}

#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif

template <typename... Ts>
std::istream& IN(Ts&... xs){ return (std::cin >> ... >> xs); }

#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)

#define Rrepr(i, a, b) for (int i = b; i >= a; i--)
#define Rrep(i, n) for (int i = n-1; i >= 0; i--)

bool dfs(ll p, vector<vector<ll>>& v,vector<ll>& fin_list, vector<ll>& cv,ll c, ll depth){
    bool closed = false;
    if(fin_list[p]){
        if(depth >= 3) return true;
        else           return false;
    }
    cv[p] = c;
    fin_list[p] = 1;
    rep(i, v[p].size()){
        if(v[p][i]){
            closed |= dfs(i, v, fin_list, cv, c, depth+1);
        }
    }
    return closed;
}

class Vsum2{
public:
    vector<vector<ll>> vsum;

    Vsum2(vector<vector<ll>>& a, 
          function<ll (ll&)> func=[](auto& a){ return a; }){
              
        ll h = a.size();
        ll w = a[0].size();
        vsum.resize(h+1, vector<ll>(w+1, 0));

        repr(i,0,h){
            ll jsum = 0;
            rep(j,w){
                jsum += func(a[i][j]);
                vsum[i+1][j+1] = jsum + vsum[i][j+1];
            }
        }
        //print("#", vsum)
    }

    ll range(ll y1,ll x1, ll y2,ll x2){
        return (vsum[y2][x2] - vsum[y2][x1] - vsum[y1][x2] + vsum[y1][x1]);
    }
};

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n,k;
    IN(n,k);

    vector<vector<ll>> a(n, vector<ll>(n, 0));
    ll amax = 0;

    rep(i,n){
        rep(j,n){
            IN(a[i][j]);
            amax = max(amax, a[i][j]);
        }
    }
    
    ll l = -1 ,r = 1e9;
    while(l+1<r){
        ll m = (l+r)/2;
        bool ok = false;

        Vsum2 asum(a, [&](auto& a){ return a > m; });
        
        rep(i,n-k+1){
            rep(j, n-k+1){
                ll sumr = asum.range(i,j, i+k,j+k);
                if(sumr < k*k/2+1){
                    ok = true;
                }
            }
        }
        
        
        if(ok){
            r=m;
        }else{
            l=m;
        }
    }
    ll ans = r;

    cout << ans << endl;

    return 0;
}

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5+3;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int n,a[N],b[N],f[N];
LL s[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>n;
  LL sum=0;
  for(int i=1;i<=n;i++)cin>>a[i]>>b[i],f[i]=i,sum+=a[i]+b[i];
  sort(f+1,f+1+n,[](int x,int y){
    return 2ll*a[x]+b[x]<2ll*a[y]+b[y];
  });
  int tot=n;
  //sum - b -2*x
  for(int i=1;i<=n;i++){
    if(sum-b[f[i]]-2ll*a[f[i]]>0){
      sum-=b[f[i]]+2ll*a[f[i]];
      tot--;
//      cout<<sum<<endl;
    }else break;

  }
  cout<<tot<<'\n';
  return 0;
}