# -*- coding: utf-8 -*- N,D = map(int, input().split()) T = [-1] K = [-1] for i in range(N): t,k = map(int, input().split()) T.append(t) K.append(k) dp = [[-1,-1]] for i in range(N): dp.append([-10000001,-10000001]) # nは何日目か,pはn日目の仕事前にどこにいるか(0:東京, 1:京都) def solution(n, p): if dp[n][p] > -10000001: return dp[n][p] price = -1 if n == N: if p==0: price = max(T[n], K[n]-D) else: price = max(T[n]-D, K[n]) else: if p==0: price = max(T[n]+solution(n+1,0), K[n]-D+solution(n+1,1)) else: price = max(T[n]-D+solution(n+1, 0), K[n]+solution(n+1, 1)) dp[n][p] = price return dp[n][p] print(solution(1, 0))