#include using namespace std; typedef long long ll; int main(){ int n,D; cin>>n>>D; ll T,K,ans=0; bool f=true;//true:tokyo false:kyoto for(int i=0;i>T>>K; if(f){ if(T>=K-D) ans+=T;else{f=false; ans+=K-D;} }else{ if(T-D>K){ ans+=T-D; f=true;}else{ans+=K;} } } cout<