n,d=map(int,input().split()) p=[] q=[] for i in range(n): a,b=map(int,input().split()) p.append(a) q.append(b) def f(x): res=0 f=-1 for _ in range(d): up=-10**18 ind=-1 for i in range(n): if i!=f and res-p[i]>=x: up=max(up,q[i]-p[i]) if up==q[i]-p[i]:ind=i if up == -10 ** 18: return False res+=up f=ind return True ok=-10**18 ng=0 while ng-ok>1: mid=(ok+ng)//2 if f(mid):ok=mid else:ng=mid print(ok)