#include using namespace std; #define REP(i, m, n) for (int i = (m); i < (int)(n); i++) #define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define reps(i, n) for (int i = 0; i <= (int)(n); i++) #define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define rreps(i, x) for (int i = (int)(x); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back typedef long long ll; typedef pair P; const int inf = INT_MAX; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); } int dp[101][2], C[101][2]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, D; cin >> N >> D; rep(i, N) cin >> C[i][0] >> C[i][1]; Fill(dp, -inf); dp[0][0] = 0; dp[0][1] = -1; rep(d, N) { rep(p, 2) { dp[d+1][p] = max(dp[d+1][p], dp[d][p] + C[d][p]); dp[d+1][1-p] = max(dp[d+1][1-p], dp[d][p] + C[d][1-p] - D); } } cout << max(dp[N][0], dp[N][1]) << endl; return 0; }