import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,D = map(int,readline().split()) m = map(int,read().split()) TK = zip(m,m) x,y = 0,-D for t,k in TK: x,y = max(x,y-D)+t, max(x-D,y)+k answer = max(x,y) print(answer)