i = input N, D = map(int, i().split()) N = list(range(N)) T, K = [], [] for t, k in [i().split() for _ in N]: T.append(int(t)) K.append(int(k)) p, q = 0, -float('inf') for n in N: p, q = max(p+T[n], q+T[n]-D), max(q+K[n], p+K[n]-D) print(max(p, q))