#include using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0;i= N) { return cost; } ll ans; if(cur == 0) { ans = max(dfs(i+1, 0, cost + T[i]), dfs(i+1, 1, cost - D + K[i])); } else { ans = max(dfs(i+1, 1, cost + K[i]), dfs(i+1, 0, cost - D + T[i])); } return ans; } int main() { cin >> N >> D; REP(i, N) { cin >> T[i] >> K[i]; } ll ans = dfs(0, 0, 0); printf("%lld\n", ans); return 0; }