import sys sys.setrecursionlimit(10000) # データを読み込む n, d = map(int, input().split()) t = [] k = [] for i in range(n): ti, ki = map(int, input().split()) t.append(ti) k.append(ki) labor_condition = [t, k] # positionにいる場合の、m日目以降の稼ぎを最大化する def search(position, m): if m ==n-1: return max(labor_condition[position][m], labor_condition[abs(position - 1)][m] - d) else: return max(labor_condition[position][m] + search(position, m+1), labor_condition[abs(position - 1)][m] - d + search(abs(position - 1), m+1)) print(search(0, 0))