def tokyo_and_kyoto(inp=None): if inp == None: n,d= map(int,input().split()) inp_l = [] for _ in range(n): inp_l.append(input()) else: 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__": print(tokyo_and_kyoto())