#include using namespace std; typedef long long ll; const int MOD = 1000000007; const int MAX_N = 110; const int INF = 1<<29; #define REP(i,n) for((i)=0;(i)<(int)(n);(i)++) int dp[MAX_N][2]; int c[MAX_N][2]; int main(){ int n, D; cin >> n >> D; for (int i = 0; i < n; i++){ cin >> c[i][0] >> c[i][1]; } dp[0][1] = -INF; for (int i = 0; i < n; i++){ dp[i + 1][0] = max(dp[i][0] + c[i][0], dp[i][1] + c[i][1] - D); dp[i + 1][1] = max(dp[i][1] + c[i][1], dp[i][0] + c[i][0] - D); } cout << max(dp[n][0], dp[n][1]) << endl; return 0; }