#include using namespace std; typedef long long LL; #define CIN_ONLY if(1) struct cww{cww(){ CIN_ONLY{ ios::sync_with_stdio(false);cin.tie(0); } }}star; #ifdef BTK #define DEBUG if(1) #else #define DEBUG if(0) #endif #define fin "\n" #define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() #define fi first #define se second #define pb push_back #define REC(ret, ...) std::function template inline bool chmin(T &l,T r) {bool a=l>r;if(a)l=r;return a;} template inline bool chmax(T &l,T r) {bool a=l istream& operator>>(istream &is,vector &v){ for(auto &it:v)is>>it; return is; } int main(){ int N,D; cin>>N>>D; LL t=0,k=-D; REP(i,N){ LL a,b; cin>>a>>b; LL tt=max(t+a,k-D+a); LL kk=max(k+b,t-D+b); t=tt; k=kk; } cout<