#include using namespace std; typedef long long int ll; int n, d; int t[110], k[110]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> d; for (int i = 0; i < n; i++) { cin >> t[i] >> k[i]; } int a, b; a = t[0]; b = k[0] - d; for (int i = 1; i < n; i++) { int c = t[i] + max(a, b - d); int e = k[i] + max(b, a - d); a = c; b = e; } cout << max(a, b) << endl; return 0; }