n, d = map(int, input().split()) pq = [] ans = -10 ** 18 pq = list(tuple(map(int, input().split())) for _ in range(n)) l = -10 ** 9 r = 0 while r - l > 1: c = (l + r) // 2 dp = [0] * n for _ in range(d): ndp = [-10 ** 9] * n mx = -10 ** 9 imx = -1 for i in range(n): if dp[i] > mx: mx = dp[i] imx = i for i, (p, q) in enumerate(pq): if i != imx and mx - p >= c: ndp[i] = mx - p + q p, q = pq[imx] for i in range(n): if i != imx and dp[i] - p >= c: ndp[i] = max(ndp[i], dp[i] - p + q) dp = ndp if max(dp) == -10 ** 9: r = c else: l = c print(l)