#include typedef long long ll; typedef unsigned long long ull; using namespace std; #define pb push_back int dy[]={0, 0, 1, -1, 1, 1, -1, -1}; int dx[]={1, -1, 0, 0, 1, -1, -1, 1}; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define mp make_pair #define fi first #define sc second ll n,d; ll t[200],k[200]; bool done[201][2]; ll memo[201][2]; ll solve(ll i,ll j) { if(done[i][j]) { return memo[i][j]; } if(i >= n) { return 0; } if(j == 0) { memo[i][j] = max(t[i] + solve(i + 1,0),k[i] + solve(i + 1,1) - d); done[i][j] = true; return memo[i][j]; } if(j == 1) { memo[i][j] = max(t[i] + solve(i + 1,0) - d,k[i] + solve(i + 1,1)); done[i][j] = true; return memo[i][j]; } } int main(){ cin >> n; cin >> d; REP(i,n) { cin >> t[i] >> k[i]; } cout << solve(0,0) << endl; return 0; }