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[n][2]; int t0 = sc.nextInt(); int k0 = sc.nextInt(); dp[0][0] = t0; dp[0][1] = k0 - d; for(int i = 1; i < n; i++) { int t = sc.nextInt(); int k = sc.nextInt(); int tokyo = Math.max(dp[i - 1][0] + t, dp[i - 1][1] + k - d); int kyoto = Math.max(dp[i - 1][0] + t - d, dp[i - 1][1] + k); dp[i][0] = tokyo; dp[i][1] = kyoto; } System.out.println(Math.max(dp[n - 1][0], dp[n - 1][1])); } }