#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; ll T[105], K[105]; ll dp[2][105]; int main(){ ll N, D; cin >> N >> D; rep(i,N){ cin >> T[i] >> K[i]; } rep(i,N){ if(i==0){ dp[0][1] = max(dp[0][1], dp[0][0] + T[0]); dp[1][1] = max(dp[1][1], dp[0][0] - D + K[0]); }else{ dp[0][i+1] = max(dp[0][i+1], dp[0][i] + T[i]); dp[1][i+1] = max(dp[1][i+1], dp[0][i] - D + K[i]); dp[0][i+1] = max(dp[0][i+1], dp[1][i] - D + T[i]); dp[1][i+1] = max(dp[1][i+1], dp[1][i] + K[i]); } } cout << max(dp[0][N], dp[1][N]) << endl; return 0; }