import java.math.BigDecimal; import java.util.Arrays; import java.util.LinkedList; import java.util.Scanner; import java.util.TreeSet; public class Main { public static long MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final long D = sc.nextLong(); long[][] DP = new long[N + 1][2]; DP[0][0] = 0; DP[0][1] = -D; // 資金がショートしないから初期化が適当でも大丈夫 for(int i = 0; i < N; i++){ final int T = sc.nextInt(); final int K = sc.nextInt(); DP[i + 1][0] = Math.max(DP[i + 1][0], DP[i][0] - 0 + T); DP[i + 1][0] = Math.max(DP[i + 1][0], DP[i][1] - D + T); DP[i + 1][1] = Math.max(DP[i + 1][1], DP[i][1] - 0 + K); DP[i + 1][1] = Math.max(DP[i + 1][1], DP[i][0] - D + K); } //System.out.println(Arrays.deepToString(DP)); System.out.println(Math.max(DP[N][0], DP[N][1])); } }