/// Author: Nguyen Thanh Phong  -  ti25phong_nt
#include <bits/stdc++.h>
using namespace std;

#define el cout << "\n";
#define FOR(i, start, end, step) for(int i=start; i<=end; i+=step)
#define FORD(i, end, start, step) for(int i=end; i>=start; i-=step)
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define popb pop_back()
#define popf pop_front()
#define ALL(x) (x).begin(),(x).end()
#define ElfariaAlbisSerfort int main()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int NN = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const long long LINF = 1e18 + 7;
const int base = 31;
const long long MOD = 1e9 + 7;
const int d4x[] = {0, 0, -1, 1};
const int d4y[] = {-1, 1, 0, 0};
const int d8x[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int d8y[] = {-1, 0, 1, -1, 1, -1, 0, 1};

/// ------------------ GLOBAL VARIABLE ------------------
ll a1, a2, b1, b2;

/// ------------------ MAIN PROGRAMME -------------------
ElfariaAlbisSerfort{
    #define NAME "paint"
    if(fopen(NAME".inp","r")){
        freopen(NAME".inp", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }

    ios_base :: sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> a1 >> a2 >> b1 >> b2;
    if(a1 > a2) swap(a1, a2);
    if(b1 > b2) swap(b1, b2);
    if(a1<b1 && a2>b2){
        cout << a2 - a1;
    }
    else if(b1<a1 && b2>a2){
        cout << b2 - b1;
    }
    else if(a1==b1 && a2==b2){
        cout << a2 - b2;
    }
    else if(a1<=b1 && a2>=b1 && a2<=b2){
        cout << b2 - a1;
    }
    else if(b1<=a1 && b2>=a1 && b2<=a2){
        cout << a2 - b1;
    }
    else{
        cout << a2-a1 +  b2-b1;
    }

    return 0;
}
