#include #include #include #include #include #include #include #include #include #include #include #include #include #define p(s) cout<<(s)<=n;i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define F first #define S second typedef long long ll; using namespace std; const ll mod = 1e9+7; ll N, D; ll dp[110][2]; ll T[110][2]; int main() { cin>>N>>D; REP(i,0,N){ cin>>T[i][0]>>T[i][1]; } dp[0][1] = -D; REP(i,0,N){ REP(j,0,2) { dp[i + 1][j] = max(dp[i+1][j], dp[i][j] + T[i][j]); dp[i + 1][1-j] = max(dp[i+1][1-j], dp[i][j] + T[i][1-j] - D); } } p(max(dp[N][0], dp[N][1])); return 0; }