#include #define fi first #define se second #define pb push_back #define sz(a) (ll)a.size() #define rep(i,n) for(ll i=0;i=0;i--) #define vec(...) vector<__VA_ARGS__> #define _3aILRlt ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) using namespace std; typedef long long ll; using pii=pair; using tpii=pair; using vi=vector; int main(){ _3aILRlt; ll n,d; cin>>n>>d; vec(pii) a(n); rep(i,n){ cin>>a[i].fi>>a[i].se; } auto f=[&](ll x)->bool{ ll now=0; vi usd(n,0); rep(_d,d){ ll maxima=-1e9,id=-1; rep(i,n){ if(usd[i]) continue; if(now-a[i].fi>=x){ if(-a[i].fi+a[i].se>maxima){ maxima=-a[i].fi+a[i].se; id=i; } } } if(id==-1){ return false; } usd[id]=1; now+=maxima; } return true; }; ll l=-1e9-1,r=1e9+1,c=-1; while(l<=r){ ll m=(l+r)/2; if(f(m)){ c=m; l=m+1; }else{ r=m-1; } } cout<