#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define int long long int
#define vi vector<int>
#define pb push_back
#define endl "\n"
#define all(v) v.begin(),v.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define deb(x) cout<<"["#x<<":"<<x<<"]"<<"  ";
#define deb2(x,y) cout<<"["#x<<":"<<x<<" "#y<<":"<<y<<"]";
#define inp int n;cin>>n;int a[n];for(int i=0;i<n;i++)cin>>a[i];
#define out(a) for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<endl;
using namespace std; 
 
 
void AKM() 
{
  int a1,b1,a2,b2;
  cin>>a1>>b1>>a2>>b2;
  if(a1==a2&&b1==b2){
    cout<<0<<endl;
    return;
  }
   if((a1-b1==a2-b2)||(a1+b1==a2+b2)||(abs(a1-a2)+abs(b1-b2)<= 3)){
    cout<<1<<endl;
    return;
  }
  if(((a1%2==a2%2)&&(b1%2==b2%2))||((a1%2!=a2%2)&&(b1%2!=b2%2))){
    cout<<2<<endl;
    return;
  }
 
  if((abs((a1+b1)-(a2+b2))<=4)||(abs((a1-b1)-(a2-b2))<=4)){
      cout<<2<<endl;
    return;
  }
  cout<<3<<endl;




  
  
        
        
 
 
}
  
int32_t main()
{
 
    fastio;
    cout<<fixed;
    cout.precision(15);
    int __TESTCASES=1;
    //cin>>__TESTCASES;
    while(__TESTCASES--){ 
    AKM();  
}
}
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b); i-- > (a); )
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

const int N = 3000 + 10, inf = 1e9 + 10, K = 5;
int a[N][K];
bool exists[1 << K];
int n;

bool f(int x) {
	rep(S, 0, 1 << K) {
		exists[S] = 0;
		rep(i, 0, n) {
			bool ok = 1;
			rep(j, 0, K) if (S >> j & 1) ok &= x <= a[i][j];
			exists[S] |= ok;
		}
	}
	rep(j, 0, n) {
		rep(i, 0, j) {
			int T = 0;
			rep(k, 0, K) if (x > max(a[i][k], a[j][k])) T |= 1 << k;
			if (exists[T]) return 1;
		}
	}
	return 0;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n;
	rep(i, 0, n) rep(j, 0, K) cin >> a[i][j];
	int l = 0, r = inf;
	while (r - l > 1) {
		// [l, r)
		int m = (l + r) / 2;
		(f(m) ? l : r) = m;
	}
	cout << l << '\n';
}