n, d = map(int,input().split()) job = [] for _ in range(n): t, k = map(int,input().split()) job.append((t,k)) #0:東京,1:京都 dp = [[0]*2 for _ in range(n)] dp[0][0] = job[0][0] dp[0][1] = job[0][1]-d for i in range(1,n): dp[i][0] = max(dp[i-1][0], dp[i-1][1]-d)+job[i][0] dp[i][1] = max(dp[i-1][0]-d, dp[i-1][1])+job[i][1] print(max(dp[n-1][0],dp[n-1][1])) #print(dp)