def tokyo_and_kyoto(inp): inp_l = inp.split("\n") n, d = map(int,inp_l.pop(0).split()) heap = [[[0],0]] for _ in range(n): l = len(heap) a, b = map(int, inp_l.pop(0).split()) for _ in range(l): path, money =heap.pop(0) if path[-1] == 0: heap.append([path+[0],money+a]) heap.append([path+[1],money+b-d]) else: heap.append([path+[0],money+a-d]) heap.append([path+[1],money+b]) heap.sort(key= lambda x:x[1],reverse=True) return heap[0][1] if __name__ == "__main__": a =" " inp = "" while " " in a: a = input() inp += a + "\n" print(tokyo_and_kyoto(inp))