#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fst first
#define snd second
#define pb push_back
#define forn(i,a,b) for(int i = a; i<b; i++)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
template <typename T>
using iset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
vector<pair<ll,ll>> oper = {{1,1},{1,-1},{1,0},{0,1},{0,-1},{-1,0},{-1,-1},{-1,1}};
int main(){
ll n,k; cin>>n>>k;
vector<pair<ll,ll>> rng(n);
forn(i,0,n){
cin>>rng[i].fst>>rng[i].snd;
}
sort(ALL(rng));
vector<ll> ini; forn(i,0,n) ini.pb(rng[i].fst);
sort(ALL(ini));
ini.erase(unique(ALL(ini)),ini.end());
//multiset<ll> ends;
iset<pair<ll,ll>> ends;
ll I = 0;
ll res = 0;
forn(i,0,SZ(ini)){
ll nini = ini[i];
while(I<n && rng[I].fst<=ini[i]){
ends.insert({rng[I].snd,I});
I++;
}
auto it = ends.find_by_order(SZ(ends)-k);
res=max(res, (*it).fst-ini[i]);
}
cout<<res<<'\n';
return 0;
}