https://codeforces.com/contest/1253/problem/E
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define f(i,l,r) for(i=(l);i<=(r);i++)
#define ff(i,r,l) for(i=(r);i>=(l);i--)
using namespace std;
const int MAXN=100005;
int n,m;
int f[MAXN<<1];
int Max;
struct A{
int l,r;
bool operator < (const A& tmp)const{
return r<tmp.r;
}
}a[MAXN];
int main()
{
int i,j,k,x,s;
cin>>n>>m;
f(i,1,m){
f[i]=m;
}
f(i,1,n){
cin>>x>>s;
a[i].l=max(1,x-s);
a[i].r=min(m,x+s);
f(j,a[i].l,a[i].r){
f[j]=0;
}
}
sort(a+1,a+1+n);
f(i,a[n].r+1,m){
f[i]=m-i+1;
}
ff(i,a[n].r,1){
if(!f[i]) f[i]=f[i+1];
else{
f(j,1,n){
if(a[j].l<i) continue;
int l=a[j].l-i;
f[i]=min(f[i],l+f[a[j].r+l+1]);
}
}
}
cout<<f[1]<<endl;
return 0;
}