#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll N, K, L, R, r=1, ans=1e18; cin >> N >> K; K--; vector> RL(N+1); for (int i=1; i<=N; i++){ cin >> L >> R; RL[i] = {R, L}; } if (K == 1){ for (auto [R, L] : RL) ans = min(ans, R-L); cout << ans << endl; return 0; } sort(RL.begin(), RL.end()); /* f(i) = iのミーティングに参加したとき、次に参加するミーティング R_i<=L_jかつR_jが最小のものを選ぶ f^(K-1)(i)<=NならOK */ vector dp(N+2), v(N+2); for (int l=1; l<=N; l++){ while(r <= N && RL[l].first > RL[r].second) r++; dp[l] = r; } iota(v.begin(), v.end(), 0); dp[N+1] = N+1; //for (int i=1; i<=N; i++) cout << dp[i] << " "; //cout << endl; while(K){ if (K&1){ for (int i=1; i<=N; i++) v[i] = v[dp[i]]; } vector pd(N+2); for (int i=1; i<=N; i++) pd[i] = dp[dp[i]]; swap(dp, pd); K >>= 1; } for (int i=1; i<=N; i++){ if (v[i] <= N){ ans = min(ans, RL[v[i]].first-RL[i].second); } } cout << (ans != 1e18 ? ans : -1) << endl; return 0; }