#include using namespace std; int main() { int N, K; cin >> N >> K; std::vector> RL(N) ; for (auto& [r, l] : RL) { cin >> l >> r; } sort(RL.begin(), RL.end()); vector nxt[20]; nxt[0].resize(N + 1); nxt[0][N] = N; { int fl = 0; for (int i = 0; i < N; i ++) { while (fl < N && RL[fl].second < RL[i].first) fl ++; nxt[0][i] = fl; } } for (int i = 1; i < 20; i ++) { for (int j = 0; j < N; j ++) { nxt[i][j] = nxt[i - 1][nxt[i - 1][j]]; } } int ans = -1; K --; for (int i = 0; i < N; i ++) { int j = i; for (int i = 0; i < 20; i ++) { if ((K >> i) & 1) { j = nxt[i][j]; } } if (j < N) { int d = RL[j].first - RL[i].second; if (ans == -1) ans = d; else ans = min(ans, d); } } cout << ans << endl; }