#include using namespace std; typedef long long ll; ll h[100001]; int n, d; int ti[110], ki[110]; int dpti[110], dpki[110]; int INF = 987654321; int main() { ios::sync_with_stdio(false); cin >> n >> d; for (int i = 1; i <= n; i++) { cin >> ti[i] >> ki[i]; } dpti[0] = 0; dpki[0] = -INF; for (int i = 1; i <=n; i++) { dpti[i] = max(dpti[i-1], dpki[i-1] - d) + ti[i]; dpki[i] = max(dpki[i-1], dpti[i-1] - d) + ki[i]; } cout << max(dpti[n], dpki[n]) << endl; return 0; }