N,D = map(int,input().split()) T =[0]*N K =[0]*N for i in range(N): T[i],K[i]=map(int,input().split()) DPT = [0]*(N+1) DPK = [0]*(N+1) DPK[0] = -10**15 for i in range(N): DPT[i+1] = max(DPT[i]+T[i],DPK[i]+T[i]-D) DPK[i+1] = max(DPK[i]+K[i],DPT[i]+K[i]-D) print(max(DPT[N],DPK[N]))