import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.math.BigDecimal; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; import static java.util.Comparator.*; public class Main { public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); Solver solver = new Solver(System.in, out); solver.solve(); out.close(); } } class Solver { Scanner sc; PrintWriter out; public Solver(InputStream in, PrintWriter out) { sc = new Scanner(in); this.out = out; } // ================================================================== int N, D; int[] T, K; int[][] mem = new int[100][2]; int calc(int now, int t) { if(now == N) return 0; if(mem[now][t] != -1) return mem[now][t]; int wk1, wk2; if(t == 1) { wk1 = calc(now + 1, 1) + T[now]; wk2 = calc(now + 1, 0) + K[now] - D; } else { wk1 = calc(now + 1, 1) + T[now] - D; wk2 = calc(now + 1, 0) + K[now]; } int ans = Math.max(wk1, wk2); return mem[now][t] = ans; } public void solve() { N = Integer.parseInt(sc.next()); D = Integer.parseInt(sc.next()); T = new int[N]; K = new int[N]; for (int i = 0; i < N; i++) { T[i] = Integer.parseInt(sc.next());; K[i] = Integer.parseInt(sc.next());; } for (int i = 0; i < mem.length; i++) { mem[i][0] = -1; mem[i][1] = -1; } out.println(calc(0, 1)); } }