#include using namespace std; //#pragma GCC optimize("Ofast") #define rep(i,n) for(ll i=0;i=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue,greater> #define all(x) (x).begin(),(x).end() #define CST(x) cout<> #define rev(x) reverse(x); using ll=long long; using vl=vector; using vvl=vector>; using pl=pair; using vpl=vector; using vvpl=vector; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[9]={1,0,-1,0,1,1,-1,-1,0}; const ll dx[9]={0,1,0,-1,1,-1,1,-1,0}; template inline bool chmin(T& a, T b) { if (a >= b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int main(){ ll n,k;cin >> n >> k; vector> v(n); rep(i,n)cin >> v[i].first.first >> v[i].first.second; rep(i,n)v[i].second=i; auto nl=v;sort(all(nl)); auto nr=v;sort(all(nr),[](pair a,pair b){return a.first.second=0&&nl[now].first.first>=nr[i].first.second){ if(chmin(rx,nl[now].first.second))idx=nl[now].second; now--; } dp[0][nr[i].second]=idx; } //rep(i,n)cout << dp[0][i] <<" ";cout << endl; rep(j,29){ rep(i,n){ if(dp[j][i]==-1){ dp[j+1][i]=-1; } else { dp[j+1][i]=dp[j][dp[j][i]]; } } } //rep(i,n)cout << dp[0][i] <<" ";cout << endl; //rep(i,n)cout << dp[1][i] <<" ";cout << endl; k--; ll ans=INF; rep(i,n){ ll now=i; rep(j,30){ if(now==-1)break; if(k>>j&1)now=dp[j][now]; } //cout << now << endl; if(now!=-1){ //cout << v[now].first.second <<" " << v[i].first.first << endl; chmin(ans,v[now].first.second-v[i].first.first); //cout << now <<" " << i << endl; } } if(ans==INF)cout << -1 << endl; else cout << ans << endl; }