from sys import stdin n, d, *indata = map(int, stdin.read().split()) offset = 0 p = [] q = [] for i in range(n): s, t = indata[offset + 2*i],indata[offset + 2*i+1] p.append(s) q.append(t) left = -10**8 right = 0 while (right - left) >= 2: mid = (right + left) // 2 dp = [[None for i in range(n)] for j in range(d)] for i in range(n): if -p[i] >= mid: dp[0][i] = q[i] - p[i] for i in range(1,d): ruisekileft = [-10**18 for i in range(n+1)] ruisekiright = [-10**18 for i in range(n+1)] for j in range(n): if dp[i-1][j] != None: ruisekileft[j+1] = max(ruisekileft[j],dp[i-1][j]) else: ruisekileft[j+1] = ruisekileft[j] if dp[i-1][n-j-1] != None: ruisekiright[j+1] = max(ruisekiright[j],dp[i-1][n-j-1]) else: ruisekiright[j+1] = ruisekiright[j] for j in range(n): kari = max(ruisekileft[j],ruisekiright[n-j-1]) if kari - p[j] >= mid: dp[i][j] = kari + q[j] - p[j] check = False for i in range(n): if dp[d-1][i] != None: check = True break if check: left = mid else: right = mid print("{}".format(left))