import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long d = sc.nextLong(); long[][] dp = new long[n][2]; long t0 = sc.nextLong(); long k0 = sc.nextLong(); dp[0][0] = t0; dp[0][1] = k0 - d; for(int i = 1; i < n; i++) { long t = sc.nextLong(); long k = sc.nextLong(); long tokyo = Math.max(dp[i - 1][0] + t, dp[i - 1][1] + t - d); long kyoto = Math.max(dp[i - 1][0] + k - 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])); } }