#include using namespace std; using ll = long long; ll N, D; ll T[101]; ll K[101]; ll ans = 0; void dfs(ll wage, int type, int i) { if (i == N) { ans = max(ans, wage); return; } if (type == 1) { if (K[i] - T[i] >= D) { dfs(wage + K[i] - D, type * -1, i + 1); } dfs(wage + T[i], type, i + 1); } else { if (T[i] - K[i] >= D) { dfs(wage + T[i] - D, type * -1, i + 1); } dfs(wage + K[i], type, i + 1); } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> D; for (ll i = 0; i < N; i++) { cin >> T[i] >> K[i]; } dfs(0, 1, 0); cout << ans << endl; return 0; }