#include <bits/stdc++.h>

using namespace std;
#define int long long
#define app push_back
const int maxn=4e5+5;
int arr[maxn];
int u[maxn][20];
const int inf=1e18;
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;cin>>n>>k;
    vector<pair<int,int> > v;vector<int> moms;
    for(int i=0;i<n;++i) {int l,r;cin>>l>>r;v.app({l,r});moms.app(l);moms.app(r);}
    sort(moms.begin(),moms.end());for(int i=0;i<v.size();++i) {v[i].first=lower_bound(moms.begin(),moms.end(),v[i].first)-moms.begin();v[i].second=lower_bound(moms.begin(),moms.end(),v[i].second)-moms.begin();}
    fill(arr,arr+maxn,inf);
    for(auto [l,r]:v)
    {
        arr[l]=min(arr[l],r);
    }
    for(int i=maxn-1;i>=1;--i) {arr[i-1]=min(arr[i-1],arr[i]);}
    for(int i=0;i<maxn;++i) u[i][0]=arr[i];
    for(int j=1;j<20;++j)
    {
        for(int i=0;i<maxn;++i)
        {
            if(u[i][j-1]==inf) u[i][j]=inf;
            else u[i][j]=u[u[i][j-1]][j-1];
        }
    }
    int res=inf;
    for(int i=0;i<maxn;++i)
    {
        int cur=i;
        for(int j=0;j<20;++j)
        {
            if(k & (1<<j))
            {
                if(cur!=inf)
                cur=u[cur][j];
            }
        }
        if(cur!=inf) res=min(res,moms[cur]-moms[i]);
    }
    cout<<(res==inf ? -1 : res);
    return 0;
}