#include using namespace std; const int MAX = 111; int n, d; long long t[MAX], k[MAX]; unordered_set dp[2]; int main() { cin >> n >> d; for (int i = 0; i < n; i++) { cin >> t[i] >> k[i]; } dp[0].insert(0); for (int i = 0; i < n; i++) { unordered_set ndp[2]; for (long long e : dp[0]) { ndp[0].insert(e + t[i]); ndp[1].insert(e + k[i] - d); } for (long long e : dp[1]) { ndp[1].insert(e + k[i]); ndp[0].insert(e + t[i] - d); } for (int j = 0; j < 2; j++) { dp[j].clear(); dp[j].insert(*max_element(ndp[j].begin(), ndp[j].end())); } } long long ans = 0; for (int i = 0; i < 2; i++) { for (long long e : dp[i]) ans = max(ans, e); } cout << ans << endl; return 0; }