import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): N, D = getlist() DP = [[0, -INF] for i in range(N + 1)] for i in range(N): T, K = getlist() DP[i + 1][0] = max(DP[i][0], DP[i][1] - D) + T DP[i + 1][1] = max(DP[i][1], DP[i][0] - D) + K ans = max(DP[-1]) # print(DP) print(ans) if __name__ == '__main__': main()