N,D = map(int,input().split()) TK = [list(map(int,input().split())) for i in range(N)] dp = [ [ 0 for j in range(2)] for i in range(1+N)] dp[0][1] = -D for i in range(N): for j in range(2): if j == 0: dp[i+1][0] = max(dp[i][0]+TK[i][0],dp[i][1]+TK[i][1] - D) if j == 1: dp[i+1][1] = max(dp[i][1]+TK[i][1],dp[i][0]+TK[i][0] - D) print(max(dp[N][0] , dp[N][1]))