import java.util.Scanner; public class No561 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int D = sc.nextInt(); int t[] = new int[N]; int k[] = new int[N]; for(int i = 0;i < N;i++) { t[i] = sc.nextInt(); k[i] = sc.nextInt(); } int tmax[] = new int[N]; int kmax[] = new int[N]; tmax[0] = t[0]; kmax[0] = k[0] - D; for(int i = 1;i < N;i++) { tmax[i] = Math.max(tmax[i-1] + t[i],kmax[i-1] + t[i] - D); kmax[i] = Math.max(kmax[i-1] + k[i],tmax[i-1] + k[i] - D); } System.out.println(Math.max(tmax[N-1], kmax[N-1])); } }