import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = sc.nextInt(); int[][] dp = new int[2][n + 1]; dp[1][0] = Integer.MIN_VALUE / 10; for (int i = 1; i <= n; i++) { int a = sc.nextInt(); int b = sc.nextInt(); dp[0][i] = Math.max(dp[0][i - 1], dp[1][i - 1] - d) + a; dp[1][i] = Math.max(dp[0][i - 1] - d, dp[1][i - 1]) + b; } System.out.println(Math.max(dp[0][n], dp[1][n])); } }