import sys input = sys.stdin.readline N, K = map(int, input().split()) LR = [] for i in range(N): L, R = map(int, input().split()) LR.append((L, R)) D = [] for i in range(N): D.append((LR[i][0], i+N)) D.append((LR[i][1], i)) D.sort(reverse=True) M = 20 dp = [[-1] * N for i in range(M)] nex = -1 for _, d in D: if d < N: dp[0][d] = nex else: d -= N if nex == -1 or LR[d][1] <= LR[nex][1]: nex = d for i in range(1, M): for j in range(N): if dp[i-1][j] != -1: dp[i][j] = dp[i-1][dp[i-1][j]] inf = 10 ** 18 ans = inf for i in range(N): now = i for j in range(M): if ((K - 1) >> j) & 1: now = dp[j][now] if now == -1: break if now != -1: ans = min(ans, LR[now][1] - LR[i][0]) print(ans) if ans != inf else print(-1)