#include <bits/stdc++.h>
#ifdef TOPOLOGY
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;

pair<int, int> p[85];
int n, m, x[85], s[85], dp[85][250003];

int rmq(int k, int i, int j) {
	i += 1 << 17;
	j += 1 << 17;
	int ans = (int)1e9;
	while (i < j) {
		if (i & 1) ans = min(ans, dp[k][i++]);
		if (!(j & 1)) ans = min(ans, dp[k][j--]);
		i >>= 1;
		j >>= 1;
	}
	if (i == j) ans = min(ans, dp[k][i]);
	return ans;
}

void upd(int k, int i, int val) {
	dp[k][i + (1 << 17)] = val - i;
	i += 1 << 17;
	i >>= 1;
	while (i) {
		dp[k][i] = min(dp[k][i * 2], dp[k][i * 2 + 1]);
		i >>= 1;
	}
}

int getdp(int k, int i) {
	return dp[k][i + (1 << 17)] + i;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p + n, [](const pair<int, int> &p1, const pair<int, int> &p2) {
		return p1.first + p1.second < p2.first + p2.second;
	});
	for (int i = 0; i < n; i++) {
		tie(x[i], s[i]) = p[i];
	}
	for (int j = 1; j <= m; j++) {
		upd(0, j, max({0, x[0] - s[0] - 1, j - x[0] - s[0]}));
	}
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= m; j++) {
			int xi = x[i];
			int si = s[i];
			int res = getdp(i - 1, j);
			int cost = 0;
			if (j > xi + si) {
				cost += j - (xi + si);
				si += cost;
			}
			int rms = min(j, max(0, min(x[i - 1] + s[i - 1], xi - si - 1)));
			int rmx = min(j, max(0, xi - si - 1));
			// int rms = max(0, min(j, min(x[i - 1] + s[i - 1], xi - si - 1)));
			// int rmx = min(j, max(x[i - 1] + s[i - 1], xi - si - 1));
			res = min(res, cost + rmq(i - 1, rms, rmx) + rmx);
			upd(i, j, res);
			// debug("dp[%d][%d] = %d, cf. %d %d\n", i, j, getdp(i, j), rms, rmx);
		}
	}
	cout << getdp(n - 1, m) << endl;
	return 0;
}


#include <bits/stdc++.h>
#ifdef TOPOLOGY
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;

pair<int, int> p[85];
int n, m, x[85], s[85], dp[85][250003];

int rmq(int k, int i, int j) {
	i += 1 << 17;
	j += 1 << 17;
	int ans = (int)1e9;
	while (i < j) {
		if (i & 1) ans = min(ans, dp[k][i++]);
		if (!(j & 1)) ans = min(ans, dp[k][j--]);
		i >>= 1;
		j >>= 1;
	}
	if (i == j) ans = min(ans, dp[k][i]);
	return ans;
}

void upd(int k, int i, int val) {
	dp[k][i + (1 << 17)] = val - i;
	i += 1 << 17;
	i >>= 1;
	while (i) {
		dp[k][i] = min(dp[k][i * 2], dp[k][i * 2 + 1]);
		i >>= 1;
	}
}

int getdp(int k, int i) {
	return dp[k][i + (1 << 17)] + i;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p + n, [](const pair<int, int> &p1, const pair<int, int> &p2) {
		return p1.first + p1.second == p2.first + p2.second ? p1.first < p2.first : p1.first + p1.second < p2.first + p2.second;
	});
	for (int i = 0; i < n; i++) {
		tie(x[i], s[i]) = p[i];
	}
	for (int j = 1; j <= m; j++) {
		upd(0, j, max({0, x[0] - s[0] - 1, j - x[0] - s[0]}));
	}
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= m; j++) {
			int xi = x[i];
			int si = s[i];
			int res = getdp(i - 1, j);
			int cost = 0;
			if (j > xi + si) {
				cost += j - (xi + si);
				si += cost;
			}
			//int rms = min(j, max(0, min(x[i - 1] + s[i - 1], xi - si - 1)));
			int rmx = min(j, max(0, xi - si - 1));
			// int rms = max(0, min(j, min(x[i - 1] + s[i - 1], xi - si - 1)));
			// int rmx = min(j, max(x[i - 1] + s[i - 1], xi - si - 1));
			res = min(res, cost + rmq(i - 1, 1, rmx) + rmx);
			upd(i, j, res);
			// debug("dp[%d][%d] = %d, cf. %d %d\n", i, j, getdp(i, j), rms, rmx);
		}
	}
	cout << getdp(n - 1, m) << endl;
	return 0;
}


#include <bits/stdc++.h>
#ifdef TOPOLOGY
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;

pair<int, int> p[85];
int n, m, x[85], s[85], dp[85][250003];

int rmq(int k, int i, int j) {
	i += 1 << 17;
	j += 1 << 17;
	int ans = (int)1e9;
	while (i < j) {
		if (i & 1) ans = min(ans, dp[k][i++]);
		if (!(j & 1)) ans = min(ans, dp[k][j--]);
		i >>= 1;
		j >>= 1;
	}
	if (i == j) ans = min(ans, dp[k][i]);
	return ans;
}

void upd(int k, int i, int val) {
	dp[k][i + (1 << 17)] = val - i;
	i += 1 << 17;
	i >>= 1;
	while (i) {
		dp[k][i] = min(dp[k][i * 2], dp[k][i * 2 + 1]);
		i >>= 1;
	}
}

int getdp(int k, int i) {
	return dp[k][i + (1 << 17)] + i;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p + n, [](const pair<int, int> &p1, const pair<int, int> &p2) {
		return p1.first + p1.second == p2.first + p2.second ? p1.first < p2.first : p1.first + p1.second < p2.first + p2.second;
	});
	for (int i = 0; i < n; i++) {
		tie(x[i], s[i]) = p[i];
	}
	for (int j = 1; j <= m; j++) {
		upd(0, j, max({0, x[0] - s[0] - 1, j - x[0] - s[0]}));
	}
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= m; j++) {
			int xi = x[i];
			int si = s[i];
			int res = getdp(i - 1, j);
			int cost = 0;
			if (j > xi + si) {
				cost += j - (xi + si);
				si += cost;
			}
			//int rms = min(j, max(0, min(x[i - 1] + s[i - 1], xi - si - 1)));
			int rmx = min(j, max(0, xi - si - 1));
			// int rms = max(0, min(j, min(x[i - 1] + s[i - 1], xi - si - 1)));
			// int rmx = min(j, max(x[i - 1] + s[i - 1], xi - si - 1));
			res = min(res, cost + rmq(i - 1, 0, rmx) + rmx);
			upd(i, j, res);
			// debug("dp[%d][%d] = %d, cf. %d %d\n", i, j, getdp(i, j), rms, rmx);
		}
	}
	cout << getdp(n - 1, m) << endl;
	return 0;
}


#include <bits/stdc++.h>
#ifdef TOPOLOGY
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;

pair<int, int> p[85];
int n, m, x[85], s[85], dp[85][250003];

int rmq(int k, int i, int j) {
	i += 1 << 17;
	j += 1 << 17;
	int ans = (int)1e9;
	while (i < j) {
		if (i & 1) ans = min(ans, dp[k][i++]);
		if (!(j & 1)) ans = min(ans, dp[k][j--]);
		i >>= 1;
		j >>= 1;
	}
	if (i == j) ans = min(ans, dp[k][i]);
	return ans;
}

void upd(int k, int i, int val) {
	dp[k][i + (1 << 17)] = val - i;
	i += 1 << 17;
	i >>= 1;
	while (i) {
		dp[k][i] = min(dp[k][i * 2], dp[k][i * 2 + 1]);
		i >>= 1;
	}
}

int getdp(int k, int i) {
	return dp[k][i + (1 << 17)] + i;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p + n, [](const pair<int, int> &p1, const pair<int, int> &p2) {
		return p1.first + p1.second == p2.first + p2.second ? p1.first < p2.first : p1.first + p1.second < p2.first + p2.second;
	});
	for (int i = 0; i < n; i++) {
		tie(x[i], s[i]) = p[i];
	}
	for (int j = 1; j <= m; j++) {
		upd(0, j, max({0, x[0] - s[0] - 1, j - x[0] - s[0]}));
	}
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= m; j++) {
			int xi = x[i];
			int si = s[i];
			int res = getdp(i - 1, j);
			int cost = 0;
			if (j > xi + si) {
				cost += j - (xi + si);
				si += cost;
			}
			int rms = min(j, max(0, min(x[i - 1] + s[i - 1], xi - si - 1)));
			int rmx = min(j, max(0, xi - si - 1));
			// int rms = max(0, min(j, min(x[i - 1] + s[i - 1], xi - si - 1)));
			// int rmx = min(j, max(x[i - 1] + s[i - 1], xi - si - 1));
			res = min(res, cost + rmq(i - 1, rms, rmx) + rmx);
			upd(i, j, res);
			// debug("dp[%d][%d] = %d, cf. %d %d\n", i, j, getdp(i, j), rms, rmx);
		}
	}
	cout << getdp(n - 1, m) << endl;
	return 0;
}


#include <bits/stdc++.h>
#ifdef TOPOLOGY
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
using namespace std;

pair<int, int> p[85];
int n, m, x[85], s[85], dp[85][250003];

int rmq(int k, int i, int j) {
	i += 1 << 17;
	j += 1 << 17;
	int ans = (int)1e9;
	while (i < j) {
		if (i & 1) ans = min(ans, dp[k][i++]);
		if (!(j & 1)) ans = min(ans, dp[k][j--]);
		i >>= 1;
		j >>= 1;
	}
	if (i == j) ans = min(ans, dp[k][i]);
	return ans;
}

void upd(int k, int i, int val) {
	dp[k][i + (1 << 17)] = val - i;
	i += 1 << 17;
	i >>= 1;
	while (i) {
		dp[k][i] = min(dp[k][i * 2], dp[k][i * 2 + 1]);
		i >>= 1;
	}
}

int getdp(int k, int i) {
	return dp[k][i + (1 << 17)] + i;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p + n, [](const pair<int, int> &p1, const pair<int, int> &p2) {
		return p1.first + p1.second == p2.first + p2.second ? p1.first > p2.first : p1.first + p1.second < p2.first + p2.second;
	});
	for (int i = 0; i < n; i++) {
		tie(x[i], s[i]) = p[i];
	}
	for (int j = 1; j <= m; j++) {
		upd(0, j, max({0, x[0] - s[0] - 1, j - x[0] - s[0]}));
	}
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= m; j++) {
			int xi = x[i];
			int si = s[i];
			int res = getdp(i - 1, j);
			int cost = 0;
			if (j > xi + si) {
				cost += j - (xi + si);
				si += cost;
			}
			int rms = min(j, max(0, min(x[i - 1] + s[i - 1], xi - si - 1)));
			int rmx = min(j, max(0, xi - si - 1));
			// int rms = max(0, min(j, min(x[i - 1] + s[i - 1], xi - si - 1)));
			// int rmx = min(j, max(x[i - 1] + s[i - 1], xi - si - 1));
			res = min(res, cost + rmq(i - 1, rms, rmx) + rmx);
			upd(i, j, res);
			// debug("dp[%d][%d] = %d, cf. %d %d\n", i, j, getdp(i, j), rms, rmx);
		}
	}
	cout << getdp(n - 1, m) << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e5+10;
const ll inf=0x3f3f3f3f;
struct node{
    int l,r;
    bool operator <(const node &t){
        return l<r;
    }
}p[100];
int dp[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,m,mx=0;cin>>n>>m;
    memset(dp,inf,sizeof dp);
    for(int i=1;i<=n;i++){
        int x,s;
        cin>>x>>s;
        p[i].l=max(1,x-s);
        p[i].r=min(m,x+s);
        mx=max(mx,p[i].r);
        for(int j=p[i].l;j<=p[i].r;j++)
            dp[j]=0;
    }
    sort(p+1,p+1+n);
    for(int i=m;i>mx;i--)dp[i]=m-i+1;
    dp[m+1]=0;
    for(int i=m;i>=1;i--)
        if(!dp[i])dp[i]=dp[i+1];
        else{
            for(int j=1;j<=n;j++)
                if(p[j].l>i){
                    int d=p[j].l-i;
                    dp[i]=min(dp[i],d+dp[min(p[j].r+d,m)+1]);
                }
        }
    cout<<dp[1]<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e5+10;
const ll inf=0x3f3f3f3f;
struct node{
    int l,r;
}p[100];
bool cmp(node a,node b){
    return a.l<b.l;
}
int dp[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,m,mx=0;cin>>n>>m;
    for(int i=0;i<=m;i++)dp[i]=inf;
    for(int i=1;i<=n;i++){
        int x,s;
        cin>>x>>s;
        p[i].l=max(1,x-s);
        p[i].r=min(m,x+s);
        mx=max(mx,p[i].r);
        for(int j=p[i].l;j<=p[i].r;j++)
            dp[j]=0;
    }
    sort(p+1,p+1+n,cmp);
    for(int i=m;i>mx;i--)dp[i]=m-i+1;
    dp[m+1]=0;
    for(int i=m;i>=1;i--)
        if(!dp[i])dp[i]=dp[i+1];
        else{
            for(int j=1;j<=n;j++)
                if(p[j].l>i){
                    int d=p[j].l-i;
                    dp[i]=min(dp[i],d+dp[min(p[j].r+d,m)+1]);
                }
        }
    cout<<dp[1]<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=2e5+10;
const ll inf=0x3f3f3f3f;
struct node{
    int l,r;
    bool operator <(const node &t){
        return l<r;
    }
}p[100];
int dp[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,m,mx=0;cin>>n>>m;
    memset(dp,inf,sizeof dp);
    for(int i=1;i<=n;i++){
        int x,s;
        cin>>x>>s;
        p[i].l=max(1,x-s);
        p[i].r=min(m,x+s);
        mx=max(mx,p[i].r);
        for(int j=p[i].l;j<=p[i].r;j++)
            dp[j]=0;
    }
    sort(p+1,p+1+n);
    for(int i=m;i>mx;i--)dp[i]=m-i+1;
    dp[m+1]=0;
    for(int i=m;i>=1;i--)
        if(!dp[i])dp[i]=dp[i+1];
        else{
            for(int j=1;j<=n;j++)
                if(p[j].l>i){
                    int d=p[j].l-i;
                    dp[i]=min(dp[i],d+dp[min(p[j].r+d,m)+1]);
                }
        }
    cout<<dp[1]<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=2e5+10;
const ll inf=0x3f3f3f3f;
struct node{
    int l,r;
    bool operator <(const node &t){
        return l<r;
    }
}p[100];
int dp[maxn];
int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,m,mx=0;scanf("%d%d",&n,&m);
    memset(dp,inf,sizeof dp);
    for(int i=1;i<=n;i++){
        int x,s;
        scanf("%d%d",&x,&s);
        p[i].l=max(1,x-s);
        p[i].r=min(m,x+s);
        mx=max(mx,p[i].r);
        for(int j=p[i].l;j<=p[i].r;j++)
            dp[j]=0;
    }
    sort(p+1,p+1+n);
    for(int i=m;i>mx;i--)dp[i]=m-i+1;
    dp[m+1]=0;
    for(int i=m;i>=1;i--)
        if(!dp[i])dp[i]=dp[i+1];
        else{
            for(int j=1;j<=n;j++)
                if(p[j].l>i){
                    int d=p[j].l-i;
                    dp[i]=min(dp[i],d+dp[min(p[j].r+d,m)+1]);
                }
        }
    printf("%d",dp[1]);
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e5+10;
const ll inf=0x3f3f3f3f;
struct node{
    int l,r;
    bool operator <(const node &t){
        return l<r;
    }
}p[100];
int dp[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,m,mx=0;cin>>n>>m;
    for(int i=0;i<=m;i++)dp[i]=inf;
    for(int i=1;i<=n;i++){
        int x,s;
        cin>>x>>s;
        p[i].l=max(1,x-s);
        p[i].r=min(m,x+s);
        mx=max(mx,p[i].r);
        for(int j=p[i].l;j<=p[i].r;j++)
            dp[j]=0;
    }
    sort(p+1,p+1+n);
    for(int i=m;i>mx;i--)dp[i]=m-i+1;
    dp[m+1]=0;
    for(int i=m;i>=1;i--)
        if(!dp[i])dp[i]=dp[i+1];
        else{
            for(int j=1;j<=n;j++)
                if(p[j].l>i){
                    int d=p[j].l-i;
                    dp[i]=min(dp[i],d+dp[min(p[j].r+d,m)+1]);
                }
        }
    cout<<dp[1]<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(n);
	for (auto &i : a) cin >> i.F >> i.S, i = { i.F-i.S, i.F+i.S };

	sort(a.begin(), a.end(), [](const pair<int, int> &x, const pair<int, int> &y){ return x.S < y.S; });

	const int N = 100000;
	const ll inf = numeric_limits<ll>::max();
	vector<ll> dp(N+2, inf);

	dp[0] = 0;
	for (auto i : a)
		for (int j = N; j > 0; --j)
		{
			int c = max(0, j - i.S);
			int l = max(0, i.F - c - 1);
			if (dp[l] != inf) dp[j] = min(dp[j], dp[l] + c);
			dp[j] = min(dp[j], dp[j+1]);
		}

	cout << dp[m] << "\n";

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

const ll linf = numeric_limits<ll>::max();

struct segment_tree
{
    int n;
    vector<ll> a;

    segment_tree(int n) : n(n), a(2 * n, linf) {}

    void update(int p, ll v)
    {
        for (p += n, a[p] = min(a[p], v); p /= 2;)
            a[p] = min(a[2 * p], a[2 * p + 1]);
    }

    ll query(int l, int r)
    {
        ll g = linf;

        for (l += n, r += n; l < r; l /= 2, r /= 2)
        {
            if (l & 1) g = min(g, a[l++]);
            if (r & 1) g = min(g, a[--r]);
        }

        return g;
    }
};

int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(n);
	for (auto &i : a) cin >> i.F >> i.S, i = { i.F-i.S, i.F+i.S };

	sort(a.begin(), a.end(), [](const pair<int, int> &x, const pair<int, int> &y){ return x.S < y.S; });

	const int N = 300000;
	segment_tree st(N+1);

	st.update(0, 0);
	for (auto i : a)
		for (int j = N; j > 0; --j)
		{
			int c = max(0, j - i.S);
			int l = max(0, i.F - c - 1);
			int r = j;
			ll cur = st.query(l, r);
			if (cur != linf)
				st.update(j, cur + c);
		}

	ll ans = linf;
	for (; m <= N; ++m)
		ans = min(ans, st.query(m, m+1));

	cout << ans << "\n";

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

const ll linf = numeric_limits<ll>::max();

struct segment_tree
{
    int n;
    vector<ll> a;

    segment_tree(int n) : n(n), a(2 * n, linf) {}

    void update(int p, ll v)
    {
        for (p += n, a[p] = min(a[p], v); p /= 2;)
            a[p] = min(a[2 * p], a[2 * p + 1]);
    }

    ll query(int l, int r)
    {
        ll g = linf;

        for (l += n, r += n; l < r; l /= 2, r /= 2)
        {
            if (l & 1) g = min(g, a[l++]);
            if (r & 1) g = min(g, a[--r]);
        }

        return g;
    }
};

int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(n);
	for (auto &i : a) cin >> i.F >> i.S, i = { i.F-i.S, i.F+i.S };

	sort(a.begin(), a.end(), [](const pair<int, int> &x, const pair<int, int> &y){ return x.S < y.S; });

	const int N = 200000;
	segment_tree st(N+1);

	st.update(0, 0);
	for (auto i : a)
		for (int j = N; j > 0; --j)
		{
			int c = max(0, j - i.S);
			int l = max(0, i.F - c - 1);
			int r = j;
			ll cur = st.query(l, r);
			if (cur != linf)
				st.update(j, cur + c);
		}

	cout << st.query(m, N+1) << "\n";

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(n);
	for (auto &i : a) cin >> i.F >> i.S, i = { i.F-i.S, i.F+i.S };

	sort(a.begin(), a.end(), [](const pair<int, int> &x, const pair<int, int> &y){ return x.S < y.S; });

	const int N = 200000;
	const ll inf = numeric_limits<ll>::max();
	vector<ll> dp(N+2, inf);

	dp[0] = 0;
	for (auto i : a)
		for (int j = N; j > 0; --j)
		{
			int c = max(0, j - i.S);
			int l = max(0, i.F - c - 1);
			if (dp[l] != inf) dp[j] = min(dp[j], dp[l] + c);
			dp[j] = min(dp[j], dp[j+1]);
		}

	cout << dp[m] << "\n";

	return 0;
}


#include <bits/stdc++.h>

#define pp push_back
#define fr(i,a,b) for(ll i=a;i<=b;++i)
#define fv(i,v) for(int i=0;i<v.size();++i)
#define ii pair<ll,ll>
#define X first
#define Y second
using namespace std;
const int N = 2e5+5;
const int M = 5e2+5;
const int mod = 1e9+7;
typedef long long ll;
///
ll f[85][N];
ii a[N];
///
bool cmp(ii& a,ii& b){
    return a.X<b.X;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>m>>n;
    memset(f,63,sizeof f);
    f[0][0]=0;
    fr(i,1,m){
        cin>>a[i].X>>a[i].Y;
    }
    sort(a+1,a+m+1,cmp);
    n=n*2;
    fr(i,1,m){
        int lf=max(1LL,a[i].X-a[i].Y);
        int rg=min(n,a[i].X+a[i].Y);
        ll pur=1e15;
        for(int j=n;j>=lf-1;--j)pur=min(pur,f[i-1][j]);

        for(int j=lf;j<=rg;++j){
            f[i][j]=min(f[i][j],pur);
        }
        for(int j=rg+1;j<=n;++j){
                if(j==50){
                    int v=2;
                    ++v;
                }
            pur=min(pur,(ll)f[i-1][max(lf-(j-rg)-1,0)]);
            f[i][j]=min(f[i][j],pur+j-rg);
        }
        fr(j,0,n)f[i][j]=min(f[i][j],f[i-1][j]);
    }
    cout<<f[m][n/2];
    return 0;
}


#include <bits/stdc++.h>

#define pp push_back
#define fr(i,a,b) for(ll i=a;i<=b;++i)
#define fv(i,v) for(int i=0;i<v.size();++i)
#define ii pair<ll,ll>
#define X first
#define Y second
using namespace std;
const int N = 2e5+5;
const int M = 5e2+5;
const int mod = 1e9+7;
typedef long long ll;
///
ll f[81][N];
ii a[N];
///
bool cmp(ii& a,ii& b){
    return a.X<b.X;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>m>>n;
    memset(f,63,sizeof f);
    f[0][0]=0;
    fr(i,1,m){
        cin>>a[i].X>>a[i].Y;
    }
    sort(a+1,a+m+1,cmp);
    n=n*2;
    fr(i,1,m){
        int lf=max(1LL,a[i].X-a[i].Y);
        int rg=min(n,a[i].X+a[i].Y);
        ll pur=1e15;
        for(int j=n;j>=lf-1;--j)pur=min(pur,f[i-1][j]);

        for(int j=lf;j<=rg;++j){
            f[i][j]=min(f[i][j],pur);
        }
        for(int j=rg+1;j<=n;++j){
            pur=min(pur,(ll)f[i-1][max(lf-(j-rg)-1,0)]);
            f[i][j]=min(f[i][j],pur+j-rg);
        }
        for(int j=n;j>=0;--j)f[i][j]=min(f[i][j],min(f[i-1][j],f[i][j+1]));
    }
    cout<<f[m][n/2];
    return 0;
}


#include <bits/stdc++.h>

#define pp push_back
#define fr(i,a,b) for(ll i=a;i<=b;++i)
#define fv(i,v) for(int i=0;i<v.size();++i)
#define ii pair<ll,ll>
#define X first
#define Y second
using namespace std;
const int N = 2e5+5;
const int M = 5e2+5;
const int mod = 1e9+7;
typedef long long ll;
///
ll f[81][N];
ii a[N];
///
bool cmp(ii& a,ii& b){
    return a.X<b.X;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>m>>n;
    memset(f,63,sizeof f);
    f[0][0]=0;
    fr(i,1,m){
        cin>>a[i].X>>a[i].Y;
    }
    sort(a+1,a+m+1,cmp);
    n=n*2;
    fr(i,1,m){
        int s=a[i].X;
        int lf=max(1LL,a[i].X-a[i].Y);
        int rg=min(n,a[i].X+a[i].Y);
        ll pur=1e15;
        for(int j=n;j>=lf-1;--j)pur=min(pur,f[i-1][j]);

        for(int j=lf;j<=rg;++j){
            f[i][j]=min(pur,f[i-1][lf-1]);
        }
        for(int j=rg+1;j<=n;++j){
                if(j==50){
                    int v=2;
                    ++v;
                }
            pur=min(pur,(ll)f[i-1][max(lf-(j-rg)-1,0)]);
            f[i][j]=min(f[i][j],pur+j-rg);
        }
        fr(j,0,n)f[i][j]=min(f[i][j],f[i-1][j]);
    }
    cout<<f[m][n/2];
    return 0;
}


#include <bits/stdc++.h>

#define pp push_back
#define fr(i,a,b) for(ll i=a;i<=b;++i)
#define fv(i,v) for(int i=0;i<v.size();++i)
#define ii pair<ll,ll>
#define X first
#define Y second
using namespace std;
const int N = 4e5+5;
const int M = 5e2+5;
const int mod = 1e9+7;
typedef long long ll;
///
ll f[85][N];
ii a[N];
///
bool cmp(ii& a,ii& b){
    return a.X<b.X;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>m>>n;
    memset(f,63,sizeof f);
    f[0][0]=0;
    fr(i,1,m){
        cin>>a[i].X>>a[i].Y;
    }
    sort(a+1,a+m+1,cmp);
    n=n*2;
    fr(i,1,m){
        int s=a[i].X;
        int lf=max(1LL,a[i].X-a[i].Y);
        int rg=min(n,a[i].X+a[i].Y);
        ll pur=1e15;
        for(int j=n;j>=lf-1;--j)pur=min(pur,f[i-1][j]);

        for(int j=lf;j<=rg;++j){
            f[i][j]=min(pur,f[i-1][lf-1]);
        }
        for(int j=rg+1;j<=n;++j){
                if(j==50){
                    int v=2;
                    ++v;
                }
            pur=min(pur,(ll)f[i-1][max(lf-(j-rg)-1,0)]);
            f[i][j]=min(f[i][j],pur+j-rg);
        }
        fr(j,0,n)f[i][j]=min(f[i][j],f[i-1][j]);
    }
    cout<<f[m][n/2];
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000007
#define pf2 pop_front
#define pb2 pop_back
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sz size
#define eps 1e-7
#define fod find_by_order
#define fastio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ofk order_of_key
#define val(x) cout << "Value dari "<< #x << " adalah " << x  << "\n"
#define tr tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};

void readf(string x){
	freopen((x+".in").c_str(),"r",stdin);
	freopen((x+".out").c_str(),"w",stdout);
}

void pr(string x){
	freopen((x+".in").c_str(),"w",stdout);
}

int fast_read()
{
	bool min = 0;
	int  result = 0;
	char ch;
	ch = getchar();
	while(1)
	{
		if(ch == '-') break;
		if(ch >='0' && ch <= '9') break;
		ch = getchar();
	}
	if(ch == '-') min = 1;else result = ch-'0';
	while(1)
	{
		ch =getchar();
		if(ch< '0' || ch>'9') break;
		result = result * 10 + (ch-'0');
	}
	if(min) return -result;
	return result;
}
//Reynaldo's Template

ll dp[85][100005];
bool vis[200005];
int n, m;

vector<pair<int, int> > v;

ll rec(ll r, ll t) {
	//cout << r << " " << t << endl;
	if (r == v.size()) return 1e18;
	if (t >= m + 1) return 0;

	if (dp[r][t] != -1) return dp[r][t];

	ll tmp = 0;

	//cout << vis[t] << " " << t  << "zz\n";

	if (vis[t]) return dp[r][t] = rec(r, t + 1);
	else {
		//cout << t << " "<< v[r].fi << "sad\n";
		if (t < v[r].fi) {
			dp[r][t] = min(rec(r + 1, t), v[r].fi - t + rec(r, v[r].se + (v[r].fi - t) + 1));
		}
		else if (t > v[r].se) {
			dp[r][t] = min(rec(r + 1, t), 1 + rec(r, t + 1));
		}
	}

	return dp[r][t];
}

int main() {
	fastio
	memset(dp, -1, sizeof dp);
	cin >> n >> m;

	for (int i = 1; i <= n; i++) {
		ll a, b;
		cin >> a >> b;
		v.pb({a - b, a + b});
	}

	sort(v.begin(), v.end());
	int mini = 1e9, maks = -1e9;
	for (int i = 0; i < v.size(); i++) {
		if (v[i].fi > maks) {
			for (int j = mini; j <= maks;j++) vis[j] = 1;
			mini = v[i].fi;
			maks = v[i].se;
		}
		else maks = max(maks, v[i].se);
		mini = max(mini, 1);
		maks = min(maks, 100000);
	}

	//cout << mini << " " << maks << "sad\n";
	for (int j = mini; j <= maks;j++) vis[j] = 1;

	cout << rec(0, 1) << "\n";
	//cout << dp[0][1] << "sad\n";

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000007
#define pf2 pop_front
#define pb2 pop_back
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sz size
#define eps 1e-7
#define fod find_by_order
#define fastio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ofk order_of_key
#define val(x) cout << "Value dari "<< #x << " adalah " << x  << "\n"
#define tr tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};

void readf(string x){
	freopen((x+".in").c_str(),"r",stdin);
	freopen((x+".out").c_str(),"w",stdout);
}

void pr(string x){
	freopen((x+".in").c_str(),"w",stdout);
}

int fast_read()
{
	bool min = 0;
	int  result = 0;
	char ch;
	ch = getchar();
	while(1)
	{
		if(ch == '-') break;
		if(ch >='0' && ch <= '9') break;
		ch = getchar();
	}
	if(ch == '-') min = 1;else result = ch-'0';
	while(1)
	{
		ch =getchar();
		if(ch< '0' || ch>'9') break;
		result = result * 10 + (ch-'0');
	}
	if(min) return -result;
	return result;
}
//Reynaldo's Template

ll dp[85][100005];
bool vis[200005];
int n, m;

vector<pair<int, int> > v;

ll rec(ll r, ll t) {
	//cout << r << " " << t << endl;
	if (r == v.size()) return 1e18;
	if (t >= m + 1) return 0;

	if (dp[r][t] != -1) return dp[r][t];

	ll tmp = 0;

	//cout << vis[t] << " " << t  << "zz\n";

	if (vis[t]) return dp[r][t] = rec(r, t + 1);
	else {
		//cout << t << " "<< v[r].fi << "sad\n";
		if (t < v[r].fi) {
			dp[r][t] = min(rec(r + 1, t), v[r].fi - t + rec(r, v[r].se + (v[r].fi - t) + 1));
		}
		else if (t > v[r].se) {
			dp[r][t] = min(rec(r + 1, t), 1 + rec(r, t + 1));
		}
	}

	return dp[r][t];
}

int main() {
	memset(dp, -1, sizeof dp);
	cin >> n >> m;

	for (int i = 1; i <= n; i++) {
		ll a, b;
		cin >> a >> b;
		v.pb({a - b, a + b});
	}

	sort(v.begin(), v.end());
	int mini = 1e9, maks = -1e9;
	for (int i = 0; i < v.size(); i++) {
		if (v[i].fi > maks) {
			for (int j = mini; j <= maks;j++) vis[j] = 1;
			mini = v[i].fi;
			maks = v[i].se;
		}
		else maks = max(maks, v[i].se);
	}

	//cout << mini << " " << maks << "sad\n";
	for (int j = mini; j <= maks;j++) vis[j] = 1;

	cout << rec(0, 1) << "\n";
	//cout << dp[0][1] << "sad\n";

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000007
#define pf2 pop_front
#define pb2 pop_back
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sz size
#define eps 1e-7
#define fod find_by_order
#define fastio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ofk order_of_key
#define val(x) cout << "Value dari "<< #x << " adalah " << x  << "\n"
#define tr tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};

void readf(string x){
	freopen((x+".in").c_str(),"r",stdin);
	freopen((x+".out").c_str(),"w",stdout);
}

void pr(string x){
	freopen((x+".in").c_str(),"w",stdout);
}

int fast_read()
{
	bool min = 0;
	int  result = 0;
	char ch;
	ch = getchar();
	while(1)
	{
		if(ch == '-') break;
		if(ch >='0' && ch <= '9') break;
		ch = getchar();
	}
	if(ch == '-') min = 1;else result = ch-'0';
	while(1)
	{
		ch =getchar();
		if(ch< '0' || ch>'9') break;
		result = result * 10 + (ch-'0');
	}
	if(min) return -result;
	return result;
}
//Reynaldo's Template

ll dp[85][100005];
bool vis[200005];
int n, m;

vector<pair<int, int> > v;

ll rec(ll r, ll t) {
	//cout << r << " " << t << endl;
	if (r == v.size()) return 1e18;
	if (t >= m + 1) return 0;

	if (dp[r][t] != -1) return dp[r][t];

	ll tmp = 0;

	//cout << vis[t] << " " << t  << "zz\n";

	if (vis[t]) return dp[r][t] = rec(r, t + 1);
	else {
		//cout << t << " "<< v[r].fi << "sad\n";
		if (t < v[r].fi) {
			dp[r][t] = min(rec(r + 1, t), v[r].fi - t + rec(r, v[r].se + (v[r].fi - t) + 1));
		}
		else if (t > v[r].se) {
			dp[r][t] = min(rec(r + 1, t), 1 + rec(r, t + 1));
		}
	}

	return dp[r][t];
}

int main() {
	fastio
	memset(dp, -1, sizeof dp);
	cin >> n >> m;

	for (int i = 1; i <= n; i++) {
		ll a, b;
		cin >> a >> b;
		v.pb({a - b, a + b});
	}

	sort(v.begin(), v.end());
	int mini = 1e9, maks = -1e9;
	for (int i = 0; i < v.size(); i++) {
		if (v[i].fi > maks) {
			for (int j = mini; j <= maks;j++) vis[j] = 1;
			mini = v[i].fi;
			maks = v[i].se;
		}
		else maks = max(maks, v[i].se);
		mini = max(mini, 1);
		maks = min(mini, 100000);
	}

	//cout << mini << " " << maks << "sad\n";
	for (int j = mini; j <= maks;j++) vis[j] = 1;

	cout << rec(0, 1) << "\n";
	//cout << dp[0][1] << "sad\n";

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000007
#define pf2 pop_front
#define pb2 pop_back
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sz size
#define eps 1e-7
#define fod find_by_order
#define fastio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ofk order_of_key
#define val(x) cout << "Value dari "<< #x << " adalah " << x  << "\n"
#define tr tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};

void readf(string x){
	freopen((x+".in").c_str(),"r",stdin);
	freopen((x+".out").c_str(),"w",stdout);
}

void pr(string x){
	freopen((x+".in").c_str(),"w",stdout);
}

int fast_read()
{
	bool min = 0;
	int  result = 0;
	char ch;
	ch = getchar();
	while(1)
	{
		if(ch == '-') break;
		if(ch >='0' && ch <= '9') break;
		ch = getchar();
	}
	if(ch == '-') min = 1;else result = ch-'0';
	while(1)
	{
		ch =getchar();
		if(ch< '0' || ch>'9') break;
		result = result * 10 + (ch-'0');
	}
	if(min) return -result;
	return result;
}
//Reynaldo's Template

ll dp[85][100005];
bool vis[100005];
int n, m;

vector<pair<int, int> > v;

ll rec(ll r, ll t) {
	//cout << r << " " << t << endl;
	if (r == v.size()) return 1e18;
	if (t >= m + 1) return 0;

	if (dp[r][t] != -1) return dp[r][t];

	ll tmp = 0;

	//cout << vis[t] << " " << t  << "zz\n";

	if (vis[t]) return dp[r][t] = rec(r, t + 1);
	else {
		//cout << t << " "<< v[r].fi << "sad\n";
		if (t < v[r].fi) {
			dp[r][t] = min(rec(r + 1, t), v[r].fi - t + rec(r, v[r].se + (v[r].fi - t) + 1));
		}
		else if (t > v[r].se) {
			dp[r][t] = min(rec(r + 1, t), 1 + rec(r, t + 1));
		}
	}

	return dp[r][t];
}

int main() {
	memset(dp, -1, sizeof dp);
	cin >> n >> m;

	for (int i = 1; i <= n; i++) {
		ll a, b;
		cin >> a >> b;
		v.pb({a - b, a + b});
	}

	sort(v.begin(), v.end());
	int mini = 1e9, maks = -1e9;
	for (int i = 0; i < v.size(); i++) {
		if (v[i].fi > maks) {
			for (int j = mini; j <= maks;j++) vis[j] = 1;
			mini = v[i].fi;
			maks = v[i].se;
		}
		else maks = max(maks, v[i].se);
	}

	//cout << mini << " " << maks << "sad\n";
	for (int j = mini; j <= maks;j++) vis[j] = 1;

	cout << rec(0, 1) << "\n";
	//cout << dp[0][1] << "sad\n";

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int dp[m+1],x[n],y[n];
    for(int i=0;i<n;i++)
    {
        int a,s;
        cin>>a>>s;
        x[i]=a-s;
        y[i]=a+s;
    }
    for(int i=0;i<=m;i++)
    {
        dp[i]=i;
        for(int j=0;j<n;j++)
        {
            if(x[j]<=i && i<=y[j])
                dp[i]=min(dp[i],dp[i-1]);
            if(y[j]>i)
                dp[i]=min(dp[i],-y[j]+i+dp[max(0,x[j]+y[j]-i-1)]);
        }
    }
    cout<<dp[m];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int dp[m+1],x[n],y[n];
    for(int i=0;i<n;i++)
    {
        int a,s;
        cin>>a>>s;
        x[i]=a-s;
        y[i]=a+s;
    }
    for(int i=0;i<=m;i++)
    {
        dp[i]=i;
        for(int j=0;j<n;j++)
        {
            if(x[j]<=i && i<=y[i])
                dp[i]=min(dp[i],dp[i-1]);
            if(y[i]>i)
                dp[i]=min(dp[i],-y[i]+i+dp[max(0,x[i]+y[i]-i-1)]);
        }
    }
    cout<<dp[m];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int dp[m+1],x[n],y[n];
    for(int i=0;i<n;i++)
    {
        int a,s;
        cin>>a>>s;
        x[i]=a-s;
        y[i]=a+s;
    }
    for(int i=0;i<=m;i++)
    {
        dp[i]=i;
        for(int j=0;j<n;j++)
        {
            if(x[j]<=i && i<=y[i])
                dp[i]=min(dp[i],dp[i-1]);
            if(y[i]>i)
                dp[i]=min(dp[i],-y[i]+i+dp[max(0,x[i]+y[i]-i-1)])
        }
    }
    cout<<dp[m];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int dp[m+1],x[n],y[n];
    for(int i=0;i<n;i++)
    {
        int a,s;
        cin>>a>>s;
        x[i]=a-s;
        y[i]=a+s;
    }
    for(int i=0;i<=m;i++)
    {
        dp[i]=i;
        for(int j=0;j<n;j++)
        {
            if(x[j]<=i && i<=y[j])
                dp[i]=min(dp[i],dp[i-1]);
            if(y[j]<i)
                dp[i]=min(dp[i],i-y[j]+dp[max(0,x[j]+y[j]-i-1)]);
        }
    }
    cout<<dp[m];
}


/*
 * Author:  heyuhhh
 * Created Time:  2019/11/17 21:59:50
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

int dp[N];
int x[N], r[N];
bool f[N];

void run(){
    for(int i = 1; i <= n; i++) {
        cin >> x[i] >> r[i];
        for(int j = max(1, x[i] - r[i]; j <= min(m, x[i] + r[i]); j++) f[j] = 1;
    }
    for(int i = 0; i <= m; i++) dp[i] = i;
    for(int i = 1; i <= m; i++) {
        if(f[i]) dp[i] = min(dp[i], dp[i - 1]);
        for(int j = 1; j <= n; j++) if(x[j] <= i) {
            int cost = max(0, i - x[j] - r[j]);
            dp[i] = min(dp[i], dp[max(0, x[j] - r[j] - 1)] + cost);
        }
    }
    cout << dp[m];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    while(cin >> n >> m) run();
	return 0;
}


/*
 * Author:  heyuhhh
 * Created Time:  2019/11/17 19:10:25
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

int n, m;
bool f[N];
int x[N], r[N];

struct Edge{
    int u,v,w,next ;
}e[N * 80];
int head[N], tot;
struct node{
    int d,u;
    bool operator < (const node &A)const{
        return d>A.d;
    }
};
void adde(int u,int v,int w){
    e[tot].v=v;e[tot].w=w;e[tot].next=head[u];head[u]=tot++;
}
int d[N];
bool vis[N];
void Dijkstra(int s){
    priority_queue <node> q;
	memset(d, INF, sizeof(d));
    memset(vis, 0, sizeof(vis)); d[s]=0;
    q.push(node{0, s});
    while(!q.empty()){
        node cur = q.top(); q.pop();
        int u = cur.u;
        if(vis[u]) continue ;
        vis[cur.u] = 1;
        for(int i = head[u]; i != -1; i = e[i].next){
            int v = e[i].v;
            if(d[v] > d[u] + e[i].w){
                d[v] = d[u] + e[i].w;
                q.push(node{d[v], v});
            }
        }
    }
}

void run(){
    memset(head, -1, sizeof(head));
    for(int i = 1; i <= n; i++) {
        cin >> x[i] >> r[i];
        for(int j = max(1, x[i] - r[i]); j <= min(m, x[i] + r[i]); j++) f[j] = 1;
    }
    for(int i = 2; i <= m; i++) {
        if(f[i] && f[i - 1]) adde(i - 1, i, 0);
        else adde(i - 1, i, 1);
    }
    for(int i = 1; i <= n; i++) {
        int L = max(1, x[i] - r[i]), R = min(m, x[i] + r[i]);
        int mx = max(L - 1, m - R);
        for(int j = 0; j <= mx; j++) {
            adde(max(1, L - j), min(m + 1, R + j + 1), j);
        }
    }
    Dijkstra(1);
    cout << d[m + 1];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    while(cin >> n >> m) run();
	return 0;
}


/*
 * Author:  heyuhhh
 * Created Time:  2019/11/17 19:10:25
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

int n, m;
bool f[N];
int x[N], r[N];

struct Edge{
    int u,v,w,next ;
}e[N * 80];
int head[N], tot;
struct node{
    int d,u;
    bool operator < (const node &A)const{
        return d>A.d;
    }
};
void adde(int u,int v,int w){
    e[tot].v=v;e[tot].w=w;e[tot].next=head[u];head[u]=tot++;
}
int d[N];
bool vis[N];
void Dijkstra(int s){
    priority_queue <node> q;
	memset(d, INF, sizeof(d));
    memset(vis, 0, sizeof(vis)); d[s]=0;
    q.push(node{0, s});
    while(!q.empty()){
        node cur = q.top(); q.pop();
        int u = cur.u;
        if(vis[u]) continue ;
        vis[cur.u] = 1;
        for(int i = head[u]; i != -1; i = e[i].next){
            int v = e[i].v;
            if(d[v] > d[u] + e[i].w){
                d[v] = d[u] + e[i].w;
                q.push(node{d[v], v});
            }
        }
    }
}

void run(){
    memset(head, -1, sizeof(head));
    for(int i = 1; i <= n; i++) {
        cin >> x[i] >> r[i];
        for(int j = max(1, x[i] - r[i]); j <= min(m, x[i] + r[i]); j++) f[j] = 1;
    }
    for(int i = 2; i <= m + 1; i++) {
        if(f[i] && f[i - 1]) adde(i - 1, i, 0);
        else adde(i - 1, i, 1);
    }
    for(int i = 1; i <= n; i++) {
        int L = max(1, x[i] - r[i]), R = min(m, x[i] + r[i]);
        int mx = max(L - 1, m - R);
        for(int j = 0; j <= mx; j++) {
            adde(max(1, L - j), min(m + 1, R + j + 1), j);
        }
    }
    Dijkstra(1);
    cout << d[m + 1];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    while(cin >> n >> m) run();
	return 0;
}


/*
 * Author:  heyuhhh
 * Created Time:  2019/11/17 21:59:50
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

int dp[N];
int x[N], r[N];
bool f[N];
int n, m;
void run(){
    for(int i = 1; i <= n; i++) {
        cin >> x[i] >> r[i];
        for(int j = max(1, x[i] - r[i]); j <= min(m, x[i] + r[i]); j++) f[j] = 1;
    }
    for(int i = 0; i <= m; i++) dp[i] = i;
    for(int i = 1; i <= m; i++) {
        if(f[i]) dp[i] = min(dp[i], dp[i - 1]);
        for(int j = 1; j <= n; j++) if(x[j] <= i) {
            int cost = max(0, i - x[j] - r[j]);
            dp[i] = min(dp[i], dp[max(0, x[j] - r[j] - cost - 1)] + cost);
        }
    }
    cout << dp[m];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    while(cin >> n >> m) run();
	return 0;
}


//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

//order_of_key(value)
//find_by_order(idx)

*/

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define all(x) x.begin(),x.end()
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (( (a)/__gcd((a), (b)) )*(b))

#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const double EPS = 1e-9;
const double PI = acos(-1);

const int MOD = 1000000007;
const int MAXN = 90;
const int MAXM = 100010;

struct Ant{
	int x, s;
};
Ant v[MAXN];

ll dp[MAXN][MAXM];
int n, m;

ll solve(int i, int j){
	if(j > m)
		return 0;

	if(i == n)
		return max(0, max( (v[i].x-v[i].s) - j, m - (v[i].x + v[i].s)));

	if(dp[i][j] != -1LL)
		return dp[i][j];

	int falta = (v[i].x-v[i].s) - j;

	if(falta <= 0)
		return dp[i][j] = solve(i+1, max(j, v[i].x + v[i].s + 1));
	else
		return dp[i][j] = min(solve(i+1, j), (ll)falta + solve(i+1, max(j, v[i].x + v[i].s + falta + 1)));
}

int main() {
	memset(dp, -1, sizeof(dp));
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	cin >> n >> m;

	for(int i=1; i<=n; i++){
		cin >> v[i].x >> v[i].s;
	}

	sort(v+1, v+n+1, [&](Ant a, Ant b){
		return (a.x-a.s) < (b.x-b.s);
	});

	cout << solve(1, 1) << endl;

	return 0;
}


//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

//order_of_key(value)
//find_by_order(idx)

*/

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define all(x) x.begin(),x.end()
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (( (a)/__gcd((a), (b)) )*(b))

#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const double EPS = 1e-9;
const double PI = acos(-1);

const int MOD = 1000000007;
const int MAXN = 90;
const int MAXM = 100010;

pii v[MAXN];

int dp[MAXN][MAXM];
int n, m;

int solve(int i, int j){
	if(j > m)
		return 0;

	if(i == n)
		return max(0, max(v[i].F - j, m - v[i].S));

	if(dp[i][j] != -1)
		return dp[i][j];

	int falta = v[i].F - j;

	if(falta <= 0)
		return dp[i][j] = solve(i+1, max(j, v[i].S + 1));
	else
		return dp[i][j] = min(solve(i+1, j), falta + solve(i+1, max(j, v[i].S + falta + 1)));
}

int main() {
	memset(dp, -1, sizeof(dp));
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	cin >> n >> m;

	for(int i=1; i<=n; i++){
		int x, s;
		cin >> x >> s;
		v[i].F = x-s;
		v[i].S = x+s;
	}

	sort(v+1, v+n+1, [&](pii a, pii b){
		return a.S < b.S;
	});

	cout << solve(1, 1) << endl;

	return 0;
}


//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

//order_of_key(value)
//find_by_order(idx)

*/

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define all(x) x.begin(),x.end()
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (( (a)/__gcd((a), (b)) )*(b))

#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const double EPS = 1e-9;
const double PI = acos(-1);

const int MOD = 1000000007;
const int MAXN = 90;
const int MAXM = 100010;

struct Ant{
	int x, s;
};
Ant v[MAXN];

ll dp[MAXN][MAXM];
int n, m;

ll solve(int i, int j){
	if(j > m)
		return 0;

	if(i == n)
		return max(0, max( (v[i].x-v[i].s) - j, m - (v[i].x + v[i].s)));

	if(dp[i][j] != -1LL)
		return dp[i][j];

	int falta = (v[i].x-v[i].s) - j;

	if(falta <= 0)
		return dp[i][j] = solve(i+1, max(j, v[i].x + v[i].s + 1));
	else
		return dp[i][j] = min(solve(i+1, j), (ll)falta + solve(i+1, max(j, v[i].x + v[i].s + falta + 1)));
}

int main() {
	memset(dp, -1, sizeof(dp));
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	cin >> n >> m;

	for(int i=1; i<=n; i++){
		cin >> v[i].x >> v[i].s;
	}

	sort(v+1, v+n+1, [&](Ant a, Ant b){
		if(a.x == b.x)
			return a.s < b.s;
		return a.x < b.x;
	});

	cout << solve(1, 1) << endl;

	return 0;
}


//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

//order_of_key(value)
//find_by_order(idx)

*/

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define all(x) x.begin(),x.end()
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (( (a)/__gcd((a), (b)) )*(b))

#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const double EPS = 1e-9;
const double PI = acos(-1);

const int MOD = 1000000007;
const int MAXN = 90;
const int MAXM = 100010;

struct Ant{
	int x, s;
};
Ant v[MAXN];

ll dp[MAXN][MAXM];
int n, m;

ll solve(int i, int j){
	if(j > m)
		return 0;

	if(i == n)
		return max(0, max( (v[i].x-v[i].s) - j, m - (v[i].x + v[i].s)));

	if(dp[i][j] != -1LL)
		return dp[i][j];

	int falta = (v[i].x-v[i].s) - j;

	if(falta <= 0)
		return dp[i][j] =min(solve(i+1, j), solve(i+1, max(j, v[i].x + v[i].s + 1)));
	else
		return dp[i][j] = min(solve(i+1, j), (ll)falta + solve(i+1, max(j, v[i].x + v[i].s + falta + 1)));
}

int main() {
	memset(dp, -1, sizeof(dp));
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	cin >> n >> m;

	for(int i=1; i<=n; i++){
		cin >> v[i].x >> v[i].s;
	}

	sort(v+1, v+n+1, [&](Ant a, Ant b){
		if(a.x-a.s == b.x-b.s)
			return a.x < b.x;
		return a.x-a.s < b.x-b.s;
	});

	cout << solve(1, 1) << endl;

	return 0;
}


//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

//order_of_key(value)
//find_by_order(idx)

*/

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define all(x) x.begin(),x.end()
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (( (a)/__gcd((a), (b)) )*(b))

#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const double EPS = 1e-9;
const double PI = acos(-1);

const int MOD = 1000000007;
const int MAXN = 90;
const int MAXM = 100010;

pii v[MAXN];

int dp[MAXN][MAXM];
int n, m;

int solve(int i, int j){
	if(j > m)
		return 0;

	if(i == n)
		return max(0, max(v[i].F - j, m - v[i].S));

	if(dp[i][j] != -1)
		return dp[i][j];

	int falta = v[i].F - j;
	dp[i][j] = solve(i, j+1) + 1;

	if(falta <= 0)
		return dp[i][j] = min(dp[i][j], solve(i+1, max(j, v[i].S + 1)));
	else
		return dp[i][j] = min(dp[i][j], min(solve(i+1, j), falta + solve(i+1, max(j, v[i].S + falta + 1))));
}

int main() {
	memset(dp, -1, sizeof(dp));
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	cin >> n >> m;

	for(int i=1; i<=n; i++){
		int x, s;
		cin >> x >> s;
		v[i].F = x-s;
		v[i].S = x+s;
	}

	sort(v+1, v+n+1, [&](pii a, pii b){
		return a.S < b.S;
	});

	cout << solve(1, 1) << endl;

	return 0;
}


//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

//order_of_key(value)
//find_by_order(idx)

*/

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define all(x) x.begin(),x.end()
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (( (a)/__gcd((a), (b)) )*(b))

#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const double EPS = 1e-9;
const double PI = acos(-1);

const int MOD = 1000000007;
const int MAXN = 90;
const int MAXM = 100010;

struct Ant{
	int x, s;
};
Ant v[MAXN];

ll dp[MAXN][MAXM];
int n, m;

ll solve(int i, int j){
	if(j > m)
		return 0;

	if(i == n)
		return max(0, max( (v[i].x-v[i].s) - j, m - (v[i].x + v[i].s)));

	if(dp[i][j] != -1LL)
		return dp[i][j];

	int falta = (v[i].x-v[i].s) - j;

	if(falta <= 0)
		return dp[i][j] = solve(i+1, max(j, v[i].x + v[i].s + 1));
	else
		return dp[i][j] = min(solve(i+1, j), (ll)falta + solve(i+1, max(j, v[i].x + v[i].s + falta + 1)));
}

int main() {
	memset(dp, -1, sizeof(dp));
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	cin >> n >> m;

	for(int i=1; i<=n; i++){
		cin >> v[i].x >> v[i].s;
	}

	sort(v+1, v+n+1, [&](Ant a, Ant b){
		if(a.x-a.s == b.x-b.s)
			return a.x < b.x;
		return a.x-a.s < b.x-b.s;
	});

	cout << solve(1, 1) << endl;

	return 0;
}


//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

//order_of_key(value)
//find_by_order(idx)

*/

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define all(x) x.begin(),x.end()
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (( (a)/__gcd((a), (b)) )*(b))

#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const double EPS = 1e-9;
const double PI = acos(-1);

const int MOD = 1000000007;
const int MAXN = 90;
const int MAXM = 100010;

pii v[MAXN];

int dp[MAXN][MAXM];
int n, m;

int solve(int i, int j){
	if(j > m)
		return 0;

	if(i == n)
		return m - j + 1;

	if(dp[i][j] != -1)
		return dp[i][j];

	int falta = v[i].F - j;
	dp[i][j] = solve(i, j+1) + 1;

	if(falta <= 0)
		return dp[i][j] = min(dp[i][j], solve(i+1, max(j, v[i].S + 1)));
	else
		return dp[i][j] = min(dp[i][j], min(solve(i+1, j), falta + solve(i+1, max(j, v[i].S + falta + 1))));
}

int main() {
	memset(dp, -1, sizeof(dp));
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	cin >> n >> m;

	for(int i=0; i<n; i++){
		int x, s;
		cin >> x >> s;
		v[i].F = x-s;
		v[i].S = x+s;
	}

	sort(v, v+n, [&](pii a, pii b){
		return a.S < b.S;
	});

	cout << solve(0, 1) << endl;

	return 0;
}


//#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

//order_of_key(value)
//find_by_order(idx)

*/

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define all(x) x.begin(),x.end()
#define endl '\n'
#define mdc(a, b) (__gcd((a), (b)))
#define mmc(a, b) (( (a)/__gcd((a), (b)) )*(b))

#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const double EPS = 1e-9;
const double PI = acos(-1);

const int MOD = 1000000007;
const int MAXN = 90;
const int MAXM = 100010;

pii v[MAXN];

int dp[MAXN][MAXM];
int n, m;

int solve(int i, int j){
	if(j > m)
		return 0;

	if(i == n)
		return max(0, max(v[i].F - j, m - v[i].S));

	if(dp[i][j] != -1)
		return dp[i][j];

	int falta = v[i].F - j;
	dp[i][j] = solve(i+1, j+1) + 1;

	if(falta <= 0)
		return dp[i][j] = min(dp[i][j], solve(i+1, max(j, v[i].S + 1)));
	else
		return dp[i][j] = min(dp[i][j], min(solve(i+1, j), falta + solve(i+1, max(j, v[i].S + falta + 1))));
}

int main() {
	memset(dp, -1, sizeof(dp));
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	cin >> n >> m;

	for(int i=1; i<=n; i++){
		int x, s;
		cin >> x >> s;
		v[i].F = x-s;
		v[i].S = x+s;
	}

	sort(v+1, v+n+1, [&](pii a, pii b){
		return a.S < b.S;
	});

	cout << solve(1, 1) << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = int;
using vl = vector<ll>;
using vs = vector<string>;
using vvl = vector<vl>;
using pll = pair<ll,ll>;
using vb = vector<bool>;

const ll oo = 0x3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define xx first
#define yy second

#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define FORD(i,a,b) for (int i=int(b)-1; i>=(a); i--)

#define rv(type,name,count) vector<type> name(count); FOR(_i,0,count) cin >> name[_i];
#define grid(type,name,c1,c2) vector<vector<type>> name(c1, vector<type>(c2)); FOR(_i,0,c1)FOR(_j,0,c2)cin >> name[_i][_j];

vvl dp;
ll n, m;
vector<pll> v;

ll rec(ll left, ll ma) {
	ll best = oo;
	if (left > m) return 0;
	if (ma >= n) return oo;
	if (dp[left][ma] != -1) return dp[left][ma];
	if (v[ma].first <= left) {
		return dp[left][ma] = rec(max(left, 1 + v[ma].first + v[ma].second), ma + 1);
	} else {
		FOR(i, ma, n) {
			ll cost = (v[i].first - v[i].second) - left;
			if (cost < 0) cost = 0;
			ll right = v[i].first + v[i].second + cost;
			ll rem = rec(right + 1, ma + 1);
			best = min(best, rem + cost);
		}
	}
	//cerr << left << ", " << ma << " returns " << best << endl;
	return dp[left][ma] = best;
}

int main() {
	cin >> n >> m;
	v = vector<pll>(n);
	FOR(i,0,n) cin >> v[i].first >> v[i].second;
	sort(all(v));
	v.pb(mp(m+1, 0));
	n++;
	dp = vvl(m+1, vl(n, -1));
	rec(1, 0);
	cout << dp[1][0] << endl;
}


#include <bits/stdc++.h>

using namespace std;

using ll = int;
using vl = vector<ll>;
using vs = vector<string>;
using vvl = vector<vl>;
using pll = pair<ll,ll>;
using vb = vector<bool>;

const ll oo = 0x3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define xx first
#define yy second

#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define FORD(i,a,b) for (int i=int(b)-1; i>=(a); i--)

#define rv(type,name,count) vector<type> name(count); FOR(_i,0,count) cin >> name[_i];
#define grid(type,name,c1,c2) vector<vector<type>> name(c1, vector<type>(c2)); FOR(_i,0,c1)FOR(_j,0,c2)cin >> name[_i][_j];

vvl dp;
ll n, m;
vector<pll> v;

ll rec(ll left, ll ma) {
	ll best = oo;
	if (left > m) return 0;
	if (ma >= n) return oo;
	if (dp[left][ma] != -1) return dp[left][ma];
	if (v[ma].first < left) {
		return dp[left][ma] = rec(left, ma + 1);
	} else {
		FOR(i, ma, n) {
			ll cost = (v[i].first - v[i].second) - left;
			if (cost < 0) cost = 0;
			ll right = v[i].first + v[i].second + cost;
			ll rem = rec(right + 1, ma + 1);
			best = min(best, rem + cost);
		}
	}
	//cerr << left << ", " << ma << " returns " << best << endl;
	return dp[left][ma] = best;
}

int main() {
	cin >> n >> m;
	v = vector<pll>(n);
	FOR(i,0,n) cin >> v[i].first >> v[i].second;
	sort(all(v));
	v.pb(mp(m+1, 0));
	n++;
	dp = vvl(m+1, vl(n, -1));
	rec(1, 0);
	cout << dp[1][0] << endl;
}


#include <bits/stdc++.h>

using namespace std;

using ll = int;
using vl = vector<ll>;
using vs = vector<string>;
using vvl = vector<vl>;
using pll = pair<ll,ll>;
using vb = vector<bool>;

const ll oo = 0x3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define xx first
#define yy second

#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define FORD(i,a,b) for (int i=int(b)-1; i>=(a); i--)

#define rv(type,name,count) vector<type> name(count); FOR(_i,0,count) cin >> name[_i];
#define grid(type,name,c1,c2) vector<vector<type>> name(c1, vector<type>(c2)); FOR(_i,0,c1)FOR(_j,0,c2)cin >> name[_i][_j];

vvl dp;
ll n, m;
vector<pll> v;

ll rec(ll left, ll ma) {
	ll best = oo;
	if (left > m) return 0;
	if (ma >= n) return oo;
	if (dp[left][ma] != -1) return dp[left][ma];
	FOR(i, ma, n) {
		ll cost = (v[i].first - v[i].second) - left;
		if (cost < 0) cost = 0;
		ll right = v[i].first + v[i].second + cost;
		ll rem = rec(right + 1, ma + 1);
		best = min(best, rem + cost);
	}

	cerr << left << ", " << ma << " returns " << best << endl;
	return dp[left][ma] = best;
}

int main() {
	cin >> n >> m;
	v = vector<pll>(n);
	FOR(i,0,n) cin >> v[i].first >> v[i].second;
	sort(all(v));
	v.pb(mp(m+1, 0));
	n++;
	dp = vvl(m+1, vl(n, -1));
	rec(1, 0);
	cout << dp[1][0] << endl;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
using vvl = vector<vl>;
using pll = pair<ll,ll>;
using vb = vector<bool>;

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define xx first
#define yy second

#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define FORD(i,a,b) for (int i=int(b)-1; i>=(a); i--)

#define rv(type,name,count) vector<type> name(count); FOR(_i,0,count) cin >> name[_i];
#define grid(type,name,c1,c2) vector<vector<type>> name(c1, vector<type>(c2)); FOR(_i,0,c1)FOR(_j,0,c2)cin >> name[_i][_j];

vvl dp;
ll n, m;
vector<pll> v;

ll rec(ll left, ll ma) {
	ll best = oo;
	if (left > m) return 0;
	if (ma >= n) return oo;
	if (dp[left][ma] != -1) return dp[left][ma];
	FOR(i, ma, n) {
		ll cost = (v[i].first - v[i].second) - left;
		if (cost < 0) cost = 0;
		ll right = v[i].first + v[i].second + cost;
		ll rem = rec(right + 1, ma + 1);
		cerr << "Query for " << right+1 << " with " << ma+1 << " gives " << rem << " at cost " << cost << endl;
		best = min(best, rem + cost);
	}

	cerr << left << ", " << ma << " returns " << best << endl;
	return dp[left][ma] = best;
}

int main() {
	cin >> n >> m;
	v = vector<pll>(n);
	FOR(i,0,n) cin >> v[i].first >> v[i].second;
	sort(all(v));
	v.pb(mp(m+1, 0));
	n++;
	dp = vvl(m+1, vl(n, -1));
	rec(1, 0);
	cout << dp[1][0] << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  int n, m; cin >> n >> m;

  vi x(n), s(n); rep(i, 0, n) cin >> x[i] >> s[i];

  vector<pii> v(n);
  rep(i, 0, n) v[i] = {x[i], s[i]};
  sort(all(v));
  rep(i, 0, n) x[i] = v[i].first, s[i] = v[i].second;

  vi dp(m+1, inf);
  dp[0] = 0;
  rep(i, 0, n){
    rep(j, 0, x[i]-s[i]){
      chmin(dp[min(m, x[i]+(x[i]-j-1))], dp[j]+(x[i]-j-1-s[i]));
    }
    rep(j, max(0LL, x[i]-s[i]-1), min(m, x[i]+s[i])+1){
      chmin(dp[min(m, x[i]+s[i])], dp[j]);
    }
    rep(j, 1, m) chmin(dp[j+1], dp[j]+1);
    for(int j = m-1; j >= 1; j--) chmin(dp[j], dp[j+1]);
  }

  cout << dp[m] << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  int n, m; cin >> n >> m;

  vi x(n), s(n); rep(i, 0, n) cin >> x[i] >> s[i];

  vector<pair<int, pii>> v(n);
  rep(i, 0, n) v[i] = {x[i]-s[i], {x[i], s[i]}};
  sort(all(v));
  rep(i, 0, n) x[i] = v[i].second.first, s[i] = v[i].second.second;

  int ans = 0;
  int covered = 1;
  rep(i, 0, n){
    if(x[i] <= covered) continue;
    int need = x[i] - covered;
    ans += need - s[i];
    covered = x[i] + need;
    if(covered >= m) break;
  }
  if(covered < m-1) ans += m-1-covered;

  rep(i, 0, n) v[i] = {x[i]+s[i], {x[i], s[i]}};
  sort(all(v));
  rep(i, 0, n) x[i] = v[i].second.first, s[i] = v[i].second.second;

  int ans2 = 0;
  covered = m;
  for(int i = n-1; i >= 0; i--){
    if(x[i] >= covered) continue;
    int need = covered - x[i];
    ans2 += need - s[i];
    covered = x[i] - need;
    if(covered < 1) break;
  }
  if(covered > 1) ans2 += covered-1;

  chmin(ans, ans2);

  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  int n, m; cin >> n >> m;

  vi x(n), s(n); rep(i, 0, n) cin >> x[i] >> s[i];

  vector<pair<int, pii>> v(n);{
    rep(i, 0, n) v[i] = {x[i]-s[i], {x[i], s[i]}};
  }
  sort(all(v));
  rep(i, 0, n) x[i] = v[i].second.first, s[i] = v[i].second.second;

  int ans = 0;
  int covered = 1;
  rep(i, 0, n){
    if(x[i] <= covered) continue;
    int need = x[i] - covered;
    ans += need - s[i];
    covered = x[i] + need;
    if(covered >= m) break;
  }
  if(covered < m-1) ans += m-1-covered;

  int ans2 = 0;
  covered = m;
  for(int i = n-1; i >= 0; i--){
    if(x[i] >= covered) continue;
    int need = covered - x[i];
    ans2 += need - s[i];
    covered = x[i] - need;
    if(covered < 1) break;
  }
  if(covered > 1) ans2 += covered-1;

  chmin(ans, ans2);

  cout << ans << endl;

  return 0;
}


import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import jdk.nashorn.internal.parser.TokenType;
import sun.net.www.content.audio.aiff;

public class A2j {

    public static void main(String[] args) {

          Scanner sc =new Scanner(System.in);
        int size=sc.nextInt();

      StringBuffer st=new StringBuffer();
      st.append(sc.next());
       for(int i=0;i<st.length()/2;i++){
           String st1=st.toString();
         for(int j=0;j<st.length()-1;){
         if((st.charAt(j)=='1'&&st.charAt(j+1)=='0')||(st.charAt(j)=='0'&&st.charAt(j+1)=='1')){st.delete(j, j+2);j+=2;}
         else{j++;}
         }

       }

        System.out.println(st.length());
       }}


import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import jdk.nashorn.internal.parser.TokenType;
import sun.net.www.content.audio.aiff;

public class A2j {

    public static void main(String[] args) {

          Scanner sc =new Scanner(System.in);
        int size=sc.nextInt();

      StringBuffer st=new StringBuffer();
      st.append(sc.next());
       for(int i=0;i<st.length();i++){
           String st1=st.toString();
         for(int j=0;j<st.length()-1;){
         if((st.charAt(j)=='1'&&st.charAt(j+1)=='0')||(st.charAt(j)=='0'&&st.charAt(j+1)=='1')){st.delete(j, j+2);j+=2;}
         else{j++;}
         }

       }

        System.out.println(st.length());
       }}


import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import jdk.nashorn.internal.parser.TokenType;
import sun.net.www.content.audio.aiff;

public class A2j {

    public static void main(String[] args) {

          Scanner sc =new Scanner(System.in);
        int size=sc.nextInt();
      int key=0;
     String st=sc.next();
     int count=0;
     int count1=0;
      for(int i=0;i<st.length();i++){
      if(st.charAt(i)=='1'){count1++;}
     else if(st.charAt(i)=='0'){count++;}
      }
        if(count>=count1){System.out.println(st.length()-(count1*2));}

             else  if(count<count1){System.out.println(st.length()-(count*2));}

       }}


import java.util.Scanner;

public class CaseOfTheZerosAndOnes {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String arg = in.next();
        int cont1 = 0;
        int cont0 = 0;
        for (int i=0; i<arg.length(); i++) {
            if(arg.substring(i,i+1).equals("0")){
                cont0++;
            }
        }
        cont1 = arg.length() - cont0;
        if(cont0 >= cont1){
            System.out.println(arg.length() - (cont1*2));
        }else{
            System.out.println(arg.length() - (cont0*2));
        }

    }

}


import java.util.Scanner;

public class CaseOfTheZerosAndOnes {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String arg = in.next();
        int contador = 0;
        while (arg.contains("10") || arg.contains("01")) {
            arg = arg.replaceFirst("10|01", "");
            contador++;
        }
        System.out.println(arg.length());

    }

}


import java.util.Scanner;

public class CaseOfTheZerosAndOnes {

    public static int eraseDigits(String arg){
    int contador = 0;
        while (arg.indexOf("10") > -1 ) {
              arg = arg.substring(arg.indexOf(
                "10")+"10".length(),arg.length());
              contador+= 2;
        }
        while (arg.indexOf("01") > -1 ) {
              arg = arg.substring(arg.indexOf(
                "01")+"01".length(),arg.length());
              contador+= 2;
        }
        return arg.length() - 2;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String arg = in.nextLine();
        System.out.println(eraseDigits(arg));
    }

}


import java.util.Scanner;

public class CaseOfTheZerosAndOnes {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String arg = in.next();
        while (arg.contains("10") || arg.contains("01")) {
            arg = arg.replaceFirst("10|01", "");
        }
        System.out.println(arg.length());

    }

}


import java.util.Scanner;

public class CaseOfTheZerosAndOnes {

    public static int calculateWords(String arg) {
        int contador = 0;
        while (arg.contains("10") || arg.contains("01")) {
            arg = arg.replaceFirst("10|01", "");
            contador++;
        }
        return arg.length();

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String arg = in.next();
        System.out.println(calculateWords(arg));

    }

}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        String n=sc.next();
        for(int i=0;i<n.length();i++){
            int j=i+1;
                if(j!=n.length() && n.charAt(i)!= n.charAt(j)){
                    n=n.substring(0, i)+n.substring(j+1, n.length());
                    System.out.println(n);
                    i=-1;
                }
        }
        System.out.println(n.length());
    }
}
// 1536712090421


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    Scanner entrada = new Scanner (System.in);
        int N = 0,n1 = 0,n2 = 0;
        N = entrada.nextInt();
        entrada.nextLine();
        String n = entrada.nextLine();
        if(n1 >= n2){
            System.out.println(n1 - n2);
        }else{
            System.out.println(n2 - n1);
        }
        for(char s:n.toCharArray()){
            if(s == '1'){
                n1 =n1 + 1;
            }else{
                n2 = n2 + 1;
            }
        }

    }
}
// 1536803140728


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size=0;
        int l = sc.nextInt();
        String n=sc.next();
        for(int i=0;i<l;i++){
            if(n.charAt(i)=='1'){
                size++;
            }
            if(n.charAt(i)=='0'){
                size--;
            }
        }

        System.out.println(Math.abs(size));
    }
}
// 1536714368530


import java.util.*;

/**
 *
 * @author Álvaro Pedreros
 */
public class Main{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int cont = 0;
        int[] x = null;
        sc.nextInt();
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();

        }
         for (int j = 0; j < n-1 ; j++) {
                if (x[j] + x[j + 1] == 1) {
                    cont++;
                }

            }

        System.out.println(n-cont);

    }

}
// 1536797550714


import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.nextLine();
        int one = 0, zero = 0;
        for (char c : s.toCharArray()) {
            if (c == '1') {
                one++;
            }
            if (c == '0') {
                zero++;
            }
        }
        if (one >= zero) {
            System.out.println(one - zero);
        } else {
            System.out.println(zero - one);
        }

    }
}
// 1536722531547


import java.util.*;

/**
 *
 * @author Pipe
 */
public class Main{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner entrada = new Scanner(System.in);
        int cont=0;
        String n = entrada.nextLine();
        int longitud = n.length();

        if(longitud>=1 && longitud<=200000){
            numero = entrada.nextInt();
        }

        cont=longitud;

        for(int i = 0; i < longitud;i++){
            if(i==1 && (i+1)==0){
                cont--;
            }else if(i==0 && (i+1)==1){
                cont--;
            }
       }
        System.out.println(cont);
// TODO code application logic here
    }
 }
// 1536790357357


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String cadena = sc.next();
        if(cadena.length() == n) {
            if( cadena.length()%2 == 0) {
                System.out.print(0);
            } else {
                System.out.print(1);
            }
        }
    }
}
// 1536704610357


import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int b,uno=0,cero=0;
        String c;
        b=sc.nextInt();
        sc.nextLine();
        c=sc.nextLine();
        for(int i=0;i<c.length();i++){
            if('1'==c.charAt(i)){
                uno++;
            }
            if('0'==c.charAt(i)){
                cero++;
            }
        }
        if(uno>=cero)
            System.out.println(uno-cero);
        else
            System.out.println(cero-uno);

    }
}
// 1536624516706


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        String n=sc.next();
        for(int i=0;i<l;i++){
            int j=i+1;
                if(j!=l && n.charAt(i)!= n.charAt(j)){
                    n=n.substring(0, i)+n.substring(j+1, l);
                    i=-1;
                    l=l-2;
                }
        }
        System.out.println(l);
    }
}
// 1536712915646


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int aux1=0,aux0=0,aux;
        for(int i=0;i<a;i++){
            int b = sc.nextInt();
            if(b==0){
                aux0++;
            }
            if(b==1){
                aux1++;
            }
        }
        aux= aux1-aux0;
        if(aux<0){
            aux*=-1;
            System.out.println(aux);
        }else{
            System.out.println(aux);
        }

    }

}

// 1536608643953


import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Easy_Problem {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        // HashMap<String, Boolean> data = new HashMap<>();
        StringBuilder a = new StringBuilder(in.next());
        StringBuilder b = new StringBuilder("");

        b.append(a.charAt(0) + "");

        for (int i = 1; i < n; i++) {

            //!(b.toString().equals(""))
     /*       if(b.length() - 1 == -1)
            {
              b.append(a.charAt(i) + "")  ;
            }
            else
            {
               b = ( (a.charAt(i) != b.charAt(b.length() - 1))) ? b.replace(b.length() - 1, (b.length() - 1) + 2, "") : b.append(a.charAt(i) + "");

            }*/
  b = (b.length() - 1 == -1) ?  b.append(a.charAt(i) + "") : ( (a.charAt(i) != b.charAt(b.length() - 1))) ? b.replace(b.length() - 1, (b.length() - 1) + 2, "") : b.append(a.charAt(i) + "");
        }

        System.out.println(b.length());

    }

}


import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Easy_Problem {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        StringBuilder a = new StringBuilder(in.next());

        HashMap<String , Boolean > data = new HashMap<>();

        data.put("0", false);
        data.put("1", true);
        for (int i = 0; i < a.length()-1; i++)
        {
            data.get(a.charAt(i)+"");
            data.get(a.charAt(i+1)+"");

            if(data.get(a.charAt(i)+"") != data.get(a.charAt(i+1)+""))
            {
                a.replace(i, i+2, "");
                i = -1 ;
            }
        /*    boolean output = data.get(a.charAt(i)+"") && data.get(a.charAt(i+1)+"") ;

            if(!output)
            {
               a.replace(i, i+2, "");
                i = -1 ;
            }
          */
        }

        System.out.println(a.length());

    }

}


import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Easy_Problem {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        StringBuilder a = new StringBuilder(in.next());

        HashMap<String , Boolean > data = new HashMap<>();

        data.put("0", false);
        data.put("1", true);
        for (int i = 0; i < a.length()-1; i++)
        {
            data.get(a.charAt(i)+"");
            data.get(a.charAt(i+1)+"");
            boolean output = data.get(a.charAt(i)+"") && data.get(a.charAt(i+1)+"") ;

            if(!output)
            {
               a.replace(i, i+2, "");
                i = -1 ;
            }

        }

        System.out.println(a.length());

    }

}


import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Easy_Problem {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        // HashMap<String, Boolean> data = new HashMap<>();
        StringBuilder a = new StringBuilder(in.next());
        StringBuilder b = new StringBuilder("");

        b.append(a.charAt(0) + "");

        for (int i = 1; i < n; i++) {

            b = (!(b.toString().equals("")) && (a.charAt(i) != b.charAt(b.length() - 1))) ? b.replace(b.length() - 1, (b.length() - 1) + 2, "") : b.append(a.charAt(i) + "");
/*
            if (!(b.toString().equals("")) && (a.charAt(i) != b.charAt(b.length() - 1))) {
                b = b.replace(b.length() - 1, (b.length() - 1) + 2, "");
            } else {
                b = b.append(a.charAt(i) + "");
            }
*/
        }

        System.out.println(b.length());

    }

}


import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
      Scanner in= new Scanner(System.in);
      String t=in.next();
      String x=in.next();
      char []n=x.toCharArray();
      int c=0,c1=0;
      for(int i=0;i<x.length();i++)
      {
          if(n[i]=='1')c++;
          else c1++;

      }
      System.out.println(Math.abs(c-c1));
    }
}


import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Easy_Problem {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        StringBuilder a = new StringBuilder(in.next());

        HashMap<String , Boolean > data = new HashMap<>();

        data.put("0", false);
        data.put("1", true);
        for (int i = 0; i < a.length()-1; i++)
        {

            if(data.get(a.charAt(i)+"") != data.get(a.charAt(i+1)+""))
            {
                a.replace(i, i+2, "");
                i = -1 ;
            }
        }

        System.out.println(a.length());

    }

}


import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Easy_Problem {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
       // HashMap<String, Boolean> data = new HashMap<>();
        StringBuilder a = new StringBuilder(in.next());
        StringBuilder b = new StringBuilder("");

        b.append(a.charAt(0) + "");

        for (int i = 1; i < n ; i++) {

            if ( !(b.toString().equals("")) && (a.charAt(i)  != b.charAt(b.length()-1)) ) {
                b.replace(b.length()-1, (b.length()-1) + 2, "");
            } else {
                b.append(a.charAt(i)  + "");
            }

        }
        /*
 ch[i] = in.next().charAt(0) ;
             boolean next  = data.get(ch[i]+"");

             if(!(current != next))
             {
               a.append(ch[i]+ch[i-1]+"");
             }
         */

        System.out.println(b.length());

    }

}


import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
      Scanner in= new Scanner(System.in);
      String t=in.next();
      String x=in.next();
      int c=0,c1=0;
      for(int i=0;i<x.length();i++)
      {
          if(x.charAt(i)=='1')c++;
          else c1++;

      }
      System.out.println(Math.abs(c-c1));
    }
}


import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Ahmed_Naser
 */
public class Easy_Problem {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        HashMap<String, Boolean> data = new HashMap<>();
        StringBuilder a = new StringBuilder(in.next());
        StringBuilder b = new StringBuilder("");
        data.put("0", false);
        data.put("1", true);

        b.append(a.charAt(0) + "");

        for (int i = 1; i < n ; i++) {

            if ( !(b.toString().equals("")) && (a.charAt(i)  != b.charAt(b.length()-1)) ) {
                b.replace(b.length()-1, (b.length()-1) + 2, "");
            } else {
                b.append(a.charAt(i)  + "");
            }

        }
        /*
 ch[i] = in.next().charAt(0) ;
             boolean next  = data.get(ch[i]+"");

             if(!(current != next))
             {
               a.append(ch[i]+ch[i-1]+"");
             }
         */

        System.out.println(b.length());

    }

}


import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int caso;
        caso = sc.nextInt();
        sc.nextLine();
        char [] cadena= new char[caso];
        String numero = new String();
        numero= sc.nextLine();
        for (int i = 0; i < numero.length(); i++) {
            cadena[i]=numero.charAt(i);
        }
        int uno=0,zero=0;
        for (int i = 0; i < cadena.length; i++) {
            if(cadena[i]=='1'){
                uno++;
            }
            if(cadena[i]=='0'){

                zero++;
        }
        }

        if(uno>=zero)
            System.out.println(uno-zero);
        else
            System.out.println(zero-uno);

    }

}

// 1536734212692


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n,unos,ceros;
        unos=0;
        ceros=0;
        String cad;
        n=sc.nextInt();
        cad=sc.next();
        for(int j=0;j<n;j++){
            if(cad.charAt(j)=='1'){
                unos++;
            }else {
                ceros++;
            }
        }
        if(ceros>unos){
            System.out.println(ceros-unos);
        }else {
            System.out.println(unos-ceros);
        }
    }

}
// 1536800625458


import java.util.Scanner;

public class Main2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.nextLine();
        int one = 0, zero = 0;
        for (char c : s.toCharArray()) {
            if (c == '1') {
                one++;
            }
            if (c == '0') {
                zero++;
            }
        }
        if (one >= zero) {
            System.out.println(one - zero);
        } else {
            System.out.println(zero - one);
        }

    }
}
// 1536722485031


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

        int uno=0,cero=0;
        Scanner sc = new Scanner(System.in);
        int tam = sc.nextInt();
            sc.nextLine();
        String en = sc.nextLine();

        for(char num : en.toCharArray()){
            if(num=='1'){
                uno++;}
            if(num=='0'){
                cero++;}
        }
        if(uno>=cero)
            System.out.println(uno-cero);
        else
            System.out.println(cero-uno);
    }

}
// 1536528665742


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    Scanner entrada = new Scanner (System.in);
        int N = 0,n1 = 0,n2 = 0;
        N = entrada.nextInt();
        entrada.nextLine();
        String n = entrada.nextLine();
        for(int i=0;i<n.charAt(i);i++){
            if(i == '1'){
                n1 =n1 + 1;
            }else{
                n2 = n2 + 1;
            }
        }
        if(n1 >= n2){
            System.out.println(n1 - n2);
        }else{
            System.out.println(n2 - n1);
        }
    }
}
// 1536803076607


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    Scanner entrada = new Scanner (System.in);
        int N = 0,n1 = 0,n2 = 0;
        N = entrada.nextInt();
        entrada.nextLine();
        String n = entrada.nextLine();
        for(char s:n.toCharArray()){
            if(s == '1'){
                n1++;
            }else{
                n2++;
            }
        }
        if(n1 >= n2){
            System.out.println(n1 - n2);
        }else{
            System.out.println(n2 - n1);
        }

    }
}
// 1536803340634


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String p = in.next();
        int count0 = 0, count1 = 0;
        while(n != p.length()){
            p = in.next();
        }
        for(int i = 0; i < n; i++){
            if(p.charAt(i)== '0'){
                count0++;
            }else{
                count1++;
            }
        }
        System.out.println(Math.abs(count1-count0));
    }
}
// 1536705217605


import java.util.*;

/**
 *
 * @author Pipe
 */
public class Maindos {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner entrada = new Scanner(System.in);
        int contONE=0,contZERO=0,resultado=0;
        entrada.nextLine();
        String n = entrada.nextLine();
        int longitud = n.length();

        for(char valor : n.toCharArray()){
            if(valor == '1'){
                contONE=contONE+1;
            }
            if(valor == '0'){
                contZERO=contZERO+1;
            }
        }

        if(contONE>=contZERO){
            resultado=contONE-contZERO;
            System.out.println(resultado);
        }else{
            resultado=contZERO-contONE;
            System.out.println(resultado);
        }
        // TODO code application logic here
    }
}
// 1536793084347


import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int z = 0; //zeros
        int o = 0; //ones
        in.nextLine();
        String s = in.nextLine();
        for(int i = 0; i < s.length();i++){
            char c = s.charAt(i);
            if(c == '1'){
                o++;
            }
            if(c == '0'){
                z++;
            }
        }
        if(o>=z){
            System.out.println(o-z);
        }
        else{
            System.out.println(z-o);
        }
    }
}
// 1536635455661


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

/**
 *
 * @author pc0128
 */
import java.util.*;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);

     int n =sc.nextInt();

     int a[]=new int[n];

     for (int i = 0; i < n; i++) {

            a[i]=sc.nextInt();

        }
        for (int i = 0; i < n-1; i++) {

                     for(int j = 1; i < n; j++){

                     if(a[i]==1)

                     }

        }

    ArrayList<Integer> pabloql = new ArrayList<>();

    pabloql./*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

/**
 *
 * @author pc0128
 */
import java.util.*;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);

     int n =sc.nextInt();

     int a[]=new int[n];

     for (int i = 0; i < n; i++) {

            a[i]=sc.nextInt();

        }
        for (int i = 0; i < n-1; i++) {

                     for(int j = 1; i < n; j++){

                     if(a[i]==1)

                     }

        }

    ArrayList<Integer> pabloql = new ArrayList<>();

    pabloql.
// 1536333460705


import java.util.*;
import java.math.*;
import java.lang.*;

public class Code {

	static Scanner sr = new Scanner(System.in);

	public static int[] getArray(int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++) {
			array[i] = sr.nextInt();
		}
		return array;
	}

	public static int[][] getMatrix(int sizeI, int sizeJ) {
		int[][] array = new int[sizeI][sizeJ];
		for (int i = 0; i < sizeI; i++) {
			for (int j = 0; j < sizeJ; j++) {
				array[i][j] = sr.nextInt();
			}
		}
		return array;
	}

	public static void main(String[] args) {

		sr.nextLine();
		String input = sr.nextLine();
		int previousStringLength = 0;
		int currentStringLength = 0;
		do{
			previousStringLength = input.length();
			input = input.replaceAll("01", "").replaceAll("10", "");
			currentStringLength = input.length();
		} while(currentStringLength != previousStringLength);
		System.out.println(input.length());	}
}


import java.util.*;
import java.math.*;
import java.lang.*;

public class Code {

	static Scanner sr = new Scanner(System.in);

	public static int[] getArray(int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++) {
			array[i] = sr.nextInt();
		}
		return array;
	}

	public static int[][] getMatrix(int sizeI, int sizeJ) {
		int[][] array = new int[sizeI][sizeJ];
		for (int i = 0; i < sizeI; i++) {
			for (int j = 0; j < sizeJ; j++) {
				array[i][j] = sr.nextInt();
			}
		}
		return array;
	}

	public static void main(String[] args) {

		sr.nextLine();
		String input = sr.nextLine();
		StringBuilder result = new StringBuilder(input);
		int previousStringLength = 0;
		int currentStringLength = 0;
		int ind1 = 0;
		int ind2 = 0;
		do {
			previousStringLength = result.length();
			ind1 = result.indexOf("01");
			ind2 = result.indexOf("10");
//			System.out.println(ind1);
//			System.out.println(ind2);
			if (ind1 < 0 && ind2 < 0) {
				break;
			}
			if (ind1 >= 0){
				result.replace(ind1, ind1 + 2, "");
			}
			if (ind2 >= 0){
				result.replace(ind2, ind2 + 2, "");
			}

			currentStringLength = result.length();
		} while (currentStringLength != previousStringLength);
		System.out.println(result.length());
		//System.out.println(result);
	}
}


import java.util.*;
import java.math.*;
import java.lang.*;

public class Code {

	static Scanner sr = new Scanner(System.in);

	public static int[] getArray(int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++) {
			array[i] = sr.nextInt();
		}
		return array;
	}

	public static int[][] getMatrix(int sizeI, int sizeJ) {
		int[][] array = new int[sizeI][sizeJ];
		for (int i = 0; i < sizeI; i++) {
			for (int j = 0; j < sizeJ; j++) {
				array[i][j] = sr.nextInt();
			}
		}
		return array;
	}

	public static void main(String[] args) {

		sr.nextLine();
		String input = sr.nextLine();
		int previousStringLength = 0;
		int currentStringLength = 0;
		do{
			previousStringLength = input.length();
			input = input.replace("01", "");
			input = input.replace("10", "");
			currentStringLength = input.length();
		} while(currentStringLength != previousStringLength);
		System.out.println(input.length());
	}
}


import java.util.*;
import java.math.*;
import java.lang.*;

public class Code {

	static Scanner sr = new Scanner(System.in);

	public static int[] getArray(int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++) {
			array[i] = sr.nextInt();
		}
		return array;
	}

	public static int[][] getMatrix(int sizeI, int sizeJ) {
		int[][] array = new int[sizeI][sizeJ];
		for (int i = 0; i < sizeI; i++) {
			for (int j = 0; j < sizeJ; j++) {
				array[i][j] = sr.nextInt();
			}
		}
		return array;
	}

	public static void main(String[] args) {

		sr.nextLine();
		String input = sr.nextLine();
		int previousStringLength = 0;
		int currentStringLength = 0;
		do{
			previousStringLength = input.length();
			input = input.replaceAll("01", "").replaceAll("10", "");
			currentStringLength = input.length();
		} while(currentStringLength != previousStringLength);
		System.out.println(input.length());
	}
}


import java.util.*;
import java.math.*;
import java.lang.*;

public class Code {

	static Scanner sr = new Scanner(System.in);

	public static int[] getArray(int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++) {
			array[i] = sr.nextInt();
		}
		return array;
	}

	public static int[][] getMatrix(int sizeI, int sizeJ) {
		int[][] array = new int[sizeI][sizeJ];
		for (int i = 0; i < sizeI; i++) {
			for (int j = 0; j < sizeJ; j++) {
				array[i][j] = sr.nextInt();
			}
		}
		return array;
	}

	public static void main(String[] args) {

		sr.nextLine();
		String input = sr.nextLine();
		StringBuilder result = new StringBuilder(input);
		int ind1 = 0;
		int ind2 = 0;

		while(true){
			ind1 = result.indexOf("01");
			if (ind1 >= 0){
				result.replace(ind1, ind1 + 2, "");
			}
			ind2 = result.indexOf("10");
			if (ind2 >= 0){
				result.replace(ind2, ind2 + 2, "");
			}
			if (ind1 < 0 && ind2 < 0) {
				break;
			}

		}
		System.out.println(result.length());
	}
}