#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, D; ll T[110] = {}; ll K[110] = {}; cin >> N >> D; for (ll i = 0; i < N; i++) { cin >> T[i] >> K[i]; } ll dp[110][2]; for (ll i = 0; i < 110; i++) { dp[i][0] = 0; dp[i][1] = 0; } dp[0][1] = -1e9; for (ll i = 0; i < N; i++) { dp[i + 1][0] = max(dp[i][0] + T[i], dp[i][1] + T[i] - D); dp[i + 1][1] = max(dp[i][0] + K[i] - D, dp[i][1] + K[i]); } cout << max(dp[N][0], dp[N][1]) << endl; return 0; }