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