import sys sys.setrecursionlimit(10**6) inf=float('inf') N,D=map(int,input().split()) T,K=[0]*N,[0]*N for i in range(N): T[i],K[i]=map(int,input().split()) dp=[[0]*2 for i in range(N+1)] dp[0][1]=-inf for i in range(N): dp[i+1][0]=max(dp[i][0]+T[i],dp[i][1]+T[i]-D) dp[i+1][1]=max(dp[i][0]+K[i]-D,dp[i][1]+K[i]) print(max(dp[N][0],dp[N][1]))