#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define mp(a,b) make_pair(a,b)
#define vi vector<int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define vp vector<pair<int,int> >
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define dom 998244353
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define pii pair<int,int> 
#define mini 2000000000000000000
#define time_taken 1.0 * clock() / CLOCKS_PER_SEC
//const long long INF=1e15;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//auto dist=uniform_int_distribution<int>(0,INF);
//const long double pi = acos(-1);
//primes for hashing 937, 1013
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<typename T, typename U> static inline void amin(T &x, U y) 
{
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
void shikhar7s(int cas)
{
    int n,i;
    cin>>n;
    vp v;
    int x,y;
    fr(i,n)
    {
        cin>>x>>y;
        v.pb(mp(y,x));
    }
    sort(all(v));
    vi a,b,aa,ba;
    i=0;
    int l=mini,r=-mini;
    while(i<n&&v[i].F==v[0].F)
    {
        a.pb(v[i].S);
        l=min(l,v[i].S);
        r=max(r,v[i].S);
        i++;
    }
    sort(all(a));
    aa.resize(sz(a));
    int j;
    fr(j,sz(a))
    {
        if(l>=0)
            aa[j]=2*r-a[j];
        else if(a[j]>0)
            aa[j]=2*(r-l)-a[j];
        else if(r>0)
            aa[j]=2*(r-l)+a[j];
        else
            aa[j]=a[j]-2*l;
    }
    rep(i,i,n)
    {
        int j=i,l=mini,r=-mini;
        while(j<n&&v[j].F==v[i].F)
        {
            b.pb(v[j].S);
            l=min(l,v[j].S);
            r=max(r,v[j].S);
            j++;
        }
        i=j-1;
        sort(all(b));
        ba.resize(sz(b),mini);
        fr(j,sz(b))
        {
            int k=lower_bound(all(a),r)-a.begin();
            if(k<sz(a))
                ba[j]=min(ba[j],aa[k]+a[k]+b[j]-2*l);
            k--;
            if(k>=0)
                ba[j]=min(ba[j],aa[k]+2*(r-l)+b[j]-a[k]);
            k=lower_bound(all(a),l)-a.begin();
            if(k<sz(a))
                ba[j]=min(ba[j],aa[k]+2*(r-l)+a[k]-b[j]);
            k--;
            if(k>=0)
                ba[j]=min(ba[j],aa[k]+2*r-a[k]-b[j]);
            // cout<<b[j]<<" "<<ba[j]<<endl;
        }
        a=b;
        aa=ba;
        b.clear();
        ba.clear();
    }
    int ans=mini;
    fr(i,sz(a))
    {
        ans=min(ans,aa[i]+abs(a[i]));
    }
    cout<<ans;
}
signed main()
{
    fast;
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    //cout<<"Case #"<<cas<<": ";
    shikhar7s(cas);
    cas++;
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define N 200000


int main(){
    int a, b;

    cin >> a >> b;
    if( a >= b ){
        for( int i = 1; i <= a; i++ ){
            cout << i << " ";
        }
        for( int i = 1; i <= b-1; i++ ){
            cout << -i << " ";
        }
        cout << -(((a+1)*a)/2 - (b-1+1)*(b-1)/2) << endl;
    }else{
        for( int i = 1; i <= b; i++ ){
            cout << -i << " ";
        }
        for( int i = 1; i <= a-1; i++ ){
            cout << i << endl;
        }
        cout << (1+b)*b/2 - (a-1+1)*(a-1)/2 << endl;
    }
}
