import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int D = scan.nextInt(); int[]T = new int[N]; int[]K = new int[N]; for(int i = 0; i < N; i++) { T[i] = scan.nextInt(); K[i] = scan.nextInt(); } scan.close(); int[][]dp = new int[N + 1][2]; dp[1][0] = T[0]; dp[1][1] = K[0] - D; for(int i = 2; i <= N; i++) { dp[i][0] = Math.max(dp[i - 1][0] + T[i - 1], dp[i - 1][1] - D + T[i - 1]); dp[i][1] = Math.max(dp[i - 1][0] - D + K[i - 1], dp[i - 1][1] + K[i - 1]); } System.out.println(Math.max(dp[N][0], dp[N][1])); } }