#include "bits/stdc++.h" #define REP(i, n, N) for(ll i=(n); i<(N); i++) #define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--) #define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr) #define SPACEREP(lst,itr) for(auto itr=lst.begin(); itr!=lst.end();++itr){cout<<*itr<<(++itr!=anslist.end()?" ":"\n");itr--;} #define CK(n, a, b) ((a)<=(n)&&(n)<(b)) #define ALL(v) (v).begin(),(v).end() #define MCP(a, b) memcpy(b,a,sizeof(b)) #define P(s) cout<<(s)<> typedef long long ll; using namespace std; const ll MOD = 1e9 + 7; const ll INF = 1e18; ll dp[101][2]; int main(){ ll n,d,tmp; cin >> n >> d; vector> input(n+1,vector(2)); REP(i,1,n+1){ REP(j,0,2){ cin >> tmp; input[i][j]=tmp; } } dp[1][0]=input[1][0]; dp[1][1]=input[1][1]-d; REP(i,1,n){ dp[i+1][0] = max(dp[i][0]+input[i+1][0],dp[i][1]+input[i+1][0]-d); dp[i+1][1] = max(dp[i][0]+input[i+1][1]-d,dp[i][1]+input[i+1][1]); } cout << max(dp[n][0],dp[n][1]) <