#include using namespace std; typedef long long int ll; int n, d; int t[110], k[110]; ll f(int i, int j) { if (i == n) return 0; if (j == 0) {//current tokyo if (k[i]-d > t[i]) { return f(i+1, 1) + k[i]-d; } else { return f(i+1, 0) + t[i]; } } else {//current kyoto if (t[i]-d > k[i]) { return f(i+1, 0) + t[i]-d; } else { return f(i+1, 1) + k[i]; } } return 0; } 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]; } cout << f(0, 0) << endl; return 0; }