import java.util.Scanner; public class Main { @SuppressWarnings("resource") public static void main(String args[]) { Scanner scanner = new Scanner(System.in); int n=scanner.nextInt(); int d=scanner.nextInt(); int t[]=new int[n+1]; int k[]=new int[n+1]; for(int i=1;i<=n;i++) { t[i]=scanner.nextInt(); k[i]=scanner.nextInt(); } int dp[][]=new int[n+1][2]; dp[0][0]=0; dp[0][1]=-d; for(int i=1;i<=n;i++) { dp[i][0]=Math.max(dp[i-1][0], dp[i-1][1]-d)+t[i]; dp[i][1]=Math.max(dp[i-1][0]-d, dp[i-1][1])+k[i]; } System.out.println(Math.max(dp[n][0], dp[n][1])); } }