#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
using namespace std;

//#include<bits/stdc++.h>



int main() {
	
	int n, d;
	cin >> n >> d;
	int r = 0;
	int f = -d;
	int T = 0;
	for (int i = 0; i < n; i++) {
		int t, k;
		cin >> t >> k;
		t = max(T, f - d) + t;
		k = max(f, T - d) + k;
		T = t;
		f = k;
	}
	cout << max(T,f) << endl;

	return 0;
}