package yukicoder; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.Scanner; public class N561 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = sc.nextInt(); int i, a, b, x; ArrayList works = new ArrayList(); LinkedList visited = new LinkedList(); LinkedList queue = new LinkedList(); for(i = 0;i < n;++i){ works.add(sc.nextInt()); works.add(sc.nextInt()); visited.add(0); visited.add(0); } queue.add(0); queue.add(1); visited.set(0, works.get(0)); visited.set(1, works.get(1) - d); while(queue.size() > 0){ i = queue.poll(); x = visited.get(i); if(i % 2 == 0){ a = i + 3; b = i + 2; }else{ a = i + 1; b = i + 2; } if(a < n*2 && works.get(a) + x - d> visited.get(a)){ visited.set(a, works.get(a) + x - d); queue.add(a); } if(b < n*2 && works.get(b) + x > visited.get(b)){ visited.set(b, works.get(b) + x); queue.add(b); } } System.out.println(Collections.max(visited)); } }