U236690
#include<bits/stdc++.h>
using namespace std;
int t,x,l[105],r[105],ans,j,maxx;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>t>>x;
if(t=1){
cin>>l[1]>>r[1];
if(l[1]!=1){
l[1]=l[1]-l[1]%x;
cout<<r[1]-l[1]<<endl;
}else{
cout<<r[1]<<endl;
}
}
for(int i=1;i<=t;i++){
cin>>l[i]>>r[i];
maxx=max(maxx,r[i]);
}
for(int i=0;i<maxx; ){
if(i+x<l[j]){
l[j]+=x;
}if(i+x==l[j]){
ans+=r[j]-l[j];
i=r[j];
j++;
}if(i+x>l[j]){
ans+=r[j]-i;
i=r[j];
j++;
}
}
cout<<ans<<endl;
return 0;
}