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