#include #include #include using namespace std; typedef long long ll; typedef pair P; #define MOD 1000000007 #define REP(i, N) for (int i = 0; i < N; ++i) #define REP1(i, N) for (int i = 1; i <= N; ++i) #define RREP(i, N) for (int i = N - 1; i >= 0; --i) #define ALL(a) a.begin(), a.end() ll dp[101][2]; int main() { int n; ll d; cin >> n >> d; ll t[n], k[n]; REP(i, n) cin >> t[i] >> k[i]; dp[1][0] = t[0]; dp[1][1] = k[0] - d; for (int i = 2; i <= n; ++i) { dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] - d) + t[i - 1]; dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] - d) + k[i - 1]; } cout << max(dp[n][0], dp[n][1]) << endl; return 0; }