#include using namespace std; using LL = long long; using ULL = unsigned long long; int dp[2][101]; int T[101], K[101]; int main() { int N, D; cin >> N >> D; for (int i = 1; i <= N; i++) cin >> T[i] >> K[i]; dp[1][0] = T[1]; dp[1][1] = K[1] - D; for (int i = 2; 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][0], dp[N][1]) << endl; }