#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } ll op(ll l, ll r){ return max(l, r); } ll e(){ return -1e14; } int main(){ // ダブリングを行う int n, k; cin >> n >> k; vector> x(n); rep(i,0,n){ ll l, r; cin >> l >> r; x[i] = pair(l, r); } sort(x.begin(), x.end(), [](const pair a, const pair b){ return pair(a.second, a.first) < pair(b.second, b.first); }); vector db(20, vector(n+1, n)); segtree seg(n); rep(i,0,n){ seg.set(i, x[i].first); } ll g; auto f = [&](ll x){ return x < g; }; rep(i,0,n){ g = x[i].second; int z = seg.max_right(i+1, f); db[0][i] = z; //cout << i << ' ' << z << endl; } rep(num,0,19){ rep(i,0,n){ db[num+1][i] = db[num][db[num][i]]; } } const ll inf = 1e18; ll ans = inf; k--; rep(i,0,n){ // kokokara start int tar = i; rep(j,0,20){ if (k >> j & 1){ tar = db[j][tar]; } } if (tar < n){ chmin(ans, x[tar].second - x[i].first); } } if (ans == inf){ cout << -1 << '\n'; }else{ cout << ans << '\n'; } }