#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; typedef long long int ll; typedef pair pi; typedef pair, ll > pii; vector vec; vector > vec2; ll MOD = 1000000007; int main(){ ll N, C; cin >> N >> C; vector > dp(105, vector(2, -1)); dp[0][0] = 0; for(ll i = 0; i < N; i++){ ll t, k; cin >> t >> k; for(ll j = 0; j < N; j++){ if(dp[i][j] == -1) continue; if(j == 0){ dp[i+1][j] = max(dp[i][j], t); dp[i+1][j+1] = max(dp[i][j], k - C); }else{ dp[i+1][j] = max(dp[i][j], k); dp[i+1][j-1] = max(dp[i][j], t - C); } } } cout << max(dp[N-1][0], dp[N-1][1]) << endl; }