import sys readline=sys.stdin.readline def Bisect_Int(ok,ng,is_ok): while abs(ok-ng)>1: mid=(ok+ng)//2 if is_ok(mid): ok=mid else: ng=mid return ok N,K=map(int,readline().split()) A,B=[],[] for _ in range(N): a,b=map(int,readline().split()) b+=1 A.append(a) B.append(b) def is_ok(ans): cnt=0 for a,b in zip(A,B): cnt+=max(0,min(b,ans)-a) return cnt