mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N, D = map(int, input().split()) P = [] Q = [] for _ in range(N): p, q = map(int, input().split()) P.append(p) Q.append(q) ok = -10 ** 9 ng = 0 mid = (ok + ng) // 2 while ng - ok > 1: prev = -1 cur = 0 flg = 1 for d in range(D): i_best = -1 cur_best = -10 ** 9 for i in range(N): if cur - P[i] < mid: continue if prev == i: continue cur_new = cur - P[i] + Q[i] if cur_new < mid: continue if cur_new > cur_best: cur_best = cur_new i_best = i if i_best == -1: flg = 0 break else: if d == 0: i_best_first = i_best prev = i_best cur = cur_best if flg == 0: prev = i_best_first cur = 0 flg = 1 for d in range(D): i_best = -1 cur_best = -10 ** 9 for i in range(N): if cur - P[i] < mid: continue if prev == i: continue cur_new = cur - P[i] + Q[i] if cur_new < mid: continue if cur_new > cur_best: cur_best = cur_new i_best = i if i_best == -1: flg = 0 break prev = i_best cur = cur_best if flg: ok = mid else: ng = mid else: ok = mid mid = (ok + ng) // 2 print(ok) if __name__ == '__main__': main()