N, D = map(int, input().split()) T, K = map(int, input().split()) dp = [[0 for i in range(2)] for j in range(N)] dp[0][0] = T dp[0][1] = K for i in range(1, N): T, K = map(int, input().split()) dp[i][0] = T + max(dp[i-1][0], dp[i-1][1] - D) dp[i][1] = K + max(dp[i-1][1], dp[i-1][0] - D) print(max(dp[N-1]))