#include<bits/stdc++.h>
using namespace std;
         
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
const int N = 200001; 

// int fexp(int a, int b,int m){int ans = 1;while(b){if(b&1)ans=(ans*a)%m; b/=2;a=(a*a)%m;}return ans;}
// int inverse(int a, int p){return fexp(a, p-2,p);} 

// int fac[2000001];

// int nCrModPFermat(int n, int r,int p) { 
//     // cout<<1<<endl;
//     if (r==0) return 1; 
//     return (((fac[n]*((((inverse(fac[r],p)%p)*inverse(fac[n-r],p))%p))))%p); 
// }

// vi prime(555,1);

void solve(){
    int a,b,x,y;cin>>a>>b>>x>>y;
    if(a==x&&y==b)cout<<0;
    else if((abs(a-x)+abs(b-y))<=3)cout<<1;
    else{
        if(abs(a-b)==abs(x-y)||abs(a+b)==abs(x+y))cout<<1;
        else if(abs(abs(a-b)-abs(x-y))<4||abs(abs(a+b)-abs(x+y))<4)cout<<2;
        else if((abs(a-b)%2)==(abs(x-y)%2))cout<<2;
        else cout<<3;
    }
}
         
signed main(){
        IOS;    
    

        int t=1; 
        // cin>>t;
        // for(int i=2; i*i<=550; i++)
        // if(prime[i])
        //     for(int j=i*i; j<=550; j+=i)
        //         prime[j]=0;
        // fac[0] = 1; 
        // for (int i=1 ; i<=100001; i++) fac[i] = fac[i-1]*i%mod; 
        rep(i,0,t){
            // cout<<"Case #"<<i+1<<": ";
            solve();
            cout<<"\n";
        }
    //    return 0;
}
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long 
#define PI 3.14159265358979323846
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(x,n) for(ll x=1;x<(ll)n+1;x++)
using namespace std;

int g1(ll g1) {
	vector<ll> a;
	bool sw = true;
	ll l1 = 1;
	while (sw) {
		if (g1 > 9) {
				a.push_back(g1 % 10);
				g1 /= 10;
				l1++;
			
		}
		else {
			a.push_back(g1);
			sw = false;
		}
	}
	sort(a.begin(), a.end());
	ll gg1 = 0;
	ll b = 1;
	rep(j, l1) {
		gg1 += a.at(j) * b;
		b *= 10;
	}
	return gg1;
}
int g2(ll g2) {
	vector<ll> a;
	bool sw = true;
	ll l1 = 1;
	while (sw) {
		if (g2 > 9) {
				a.push_back(g2 % 10);
				g2 /= 10;
				l1++;
		}
		else {
			a.push_back(g2);
			sw = false;
		}
	}
	sort(a.begin(), a.end(),greater<ll>());
	ll gg2 = 0;
	ll b = 1;
	rep(j, l1) {
		gg2 += a.at(j) * b;
		b *= 10;
	}
	return gg2;
}

int main() {
	ll N;
	ll sw = 0;
	cin >> N;
	vector <ll> A(N), P(N), X(N);
	rep(i, N) cin >> A.at(i) >> P.at(i) >> X.at(i);
	vector<ll> B;
	rep(i, N) {
		if (A.at(i) < X.at(i)) {
			B.push_back(P.at(i));
			sw++;
		}
	}
		if (sw == 0) {
			cout << "-1" << endl;
			return 0;
		}
		else {
			sort(B.begin(), B.end());
			cout << B.at(0) << endl;
			return 0;
		}
	
}
