package yukicoder; import java.util.Scanner; import static java.lang.Math.max; public class No561 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), d = sc.nextInt(); int t, k, beforeT, beforeK; int resultT = 0, resultK = 0; boolean tokyo = true; beforeT = sc.nextInt(); beforeK = sc.nextInt() - d; for(int i = 0; i < n - 1; i++) { t = sc.nextInt(); k = sc.nextInt(); resultT = t + max(beforeT, beforeK - d); resultK = k + max(beforeK, beforeT - d); beforeT = resultT; beforeK = resultK; } System.out.println(max(resultT, resultK)); } }