#include typedef long long ll; using namespace std; int INF = 1e9; int MOD = 1e9+7; int dp[2][1000]; main(){ int N,D,T[1000],K[1000]; cin >> N >> D; for(int i = 0;i < N;i++)cin >> T[i] >> K[i]; for(int i = 0;i < N;i++)cout << T[i] << K[i] << endl; dp[0][0] = T[0]; dp[1][0] = K[0] - D; for(int i = 1;i < N;i++){ dp[0][i] = max(dp[0][i-1]+T[i] ,dp[1][i-1]+T[i]-D); dp[1][i] = max(dp[0][i-1]+K[i]-D,dp[1][i-1]+K[i]); } cout << max(dp[0][N-1],dp[1][N-1]) << endl; }