N,D = map(int,input().split()) income = [tuple(map(int,input().split())) for _ in range(N)] dp0,dp1 = 0,-10**10 for T,K in income: today0 = max(dp0 + T,dp1 - D + T) today1 = max(dp1 + K,dp0 - D + K) dp0,dp1 = today0,today1 ans = max(dp0,dp1) print(ans)