#include #include #include #include #include #include /* #include #include #include #include #include */ using namespace std; typedef long long ll; //typedef pair P; #define rep(i, m) for(ll i=0;i> N >> D; rep(i, N) { cin >> T[i][0] >> T[i][1]; } rep(i, N+1) { dp[i][0] = -INF; dp[i][1] = -INF; } dp[0][0] = 0; dp[0][1] = -D; rep(i,N) { rep(j, 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); } } cout << max({dp[N][0], dp[N][1] }) << endl; }