#include <iostream>
#include <algorithm>
#include <vector>
#define forn(i,n) for(int i=0;i<(int)n;++i)
#define ALL(v) v.begin(),v.end()
#define SZ(v) (int)v.size()
using namespace std;
const int INF = 90000000;
int n, k;
vector<int> l, r;
bool check(int m){
vector<pair<int,int>> es; // eventos
forn(i,n){
if(r[i] - m < l[i]) continue; // no me sirve
es.push_back({l[i],+1});
es.push_back({r[i]-m+1,-1}); // desactivacion
}
sort(ALL(es));
int cnt = 0;
forn(i,SZ(es)){
int j=i;
while(j<SZ(es) && es[j].first == es[i].first){
cnt += es[j++].second;
}
if(cnt >= k) return 1;
i = j-1;
}
return 0;
}
void solve(){
cin>>n>>k;
l.resize(n);
r.resize(n);
forn(i,n) cin>>l[i]>>r[i];
int L = 0, R = INF;
while(R-L>1){
int M=(L+R)/2;
if(check(M)) L = M;
else R = M;
}
cout<<L<<"\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef LOCAL
freopen("B.in", "r", stdin);
int tcs; cin>>tcs;
while(tcs--)
#endif
solve();
return 0;
}