import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(1, in, out); out.close(); } static class Task { int[][] dp; public void solve(int testNumber, Scanner in, PrintWriter out) { final int n = in.nextInt(); final int d = in.nextInt(); final int[] t = new int[n]; final int[] k = new int[n]; for (int i = 0; i < n; i++) { t[i] = in.nextInt(); k[i] = in.nextInt(); } dp = new int[n][2]; // dp[day][tokyo or kyoto] dp[0][0] = t[0]; dp[0][1] = k[0] - d; for (int i = 1; i < n; i++) { dp[i][0] = Math.max(dp[i - 1][0] + t[i], dp[i - 1][1] + t[i] - d); dp[i][1] = Math.max(dp[i - 1][0] + k[i] - d, dp[i - 1][1] + k[i]); } out.println(Math.max(dp[n - 1][0], dp[n - 1][1])); } } }