#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll n;
    cin >> n;
    vector<pair<int, int>> a(n + 1);
    int empty = 0;
    vector<int> fl(n * 2 + 10, empty);
    REP(i, 1, n + 1)
    {
        cin >> a[i].first >> a[i].second;
        if (a[i].first != -1)
        {
            if (fl[a[i].first] != empty)
            {
                cout << "No" << endl;
                return 0;
            }
            fl[a[i].first] = i;
        }
        else
            a[i].first = empty;
        if (a[i].second != -1)
        {
            if (fl[a[i].second] != empty)
            {
                cout << "No" << endl;
                return 0;
            }
            fl[a[i].second] = -i;
        }
        else
            a[i].second = empty;
    }

    auto ok = [&](int l, int r) {
        if (r > 2 * n || fl[l] < 0 || fl[r] > 0)
            return false;
        if (fl[l] == empty && fl[r] == empty)
            return true;
        if (fl[l] == empty && fl[r] < 0 && a[-fl[r]].first == empty)
            return true;
        if (fl[r] == empty && fl[l] > 0 && a[fl[l]].second == empty)
            return true;
        if (fl[l] == -fl[r])
            return true;
        return false;
    };

    auto solve = [&](int l, int r) {
        int d = r - l;
        if (!ok(l, r))
            return false;

        REP(i, l + 1, r)
        {
            if (!ok(i, i + d))
                return false;
        }

        return true;
    };

    vector<bool> dp(2 * n + 2);
    dp[1] = 1;

    REP(i, 1, 2 * n)
    if (dp[i] && fl[i] >= 0)
    {
        if (fl[i] > 0)
        {
            if (a[fl[i]].second != empty)
            {
                if (solve(i, a[fl[i]].second))
                {
                    dp[2 * a[fl[i]].second - i] = 1;
                }
            }
            else
            {
                REP(j, i + 1, 2 * n + 1)
                if (solve(i, j))
                {
                    dp[2 * j - i] = 1;
                }
            }
        }
        else
        {
            REP(j, i + 1, 2 * n + 1)
            {
                if (solve(i, j))
                {
                    dp[2 * j - i] = 1;
                }
            }
        }
    }

    if (dp.back())
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

struct point {
  ll x, y;
};
int main(void) {
  point s, g;
  cin >> s.x >> s.y >> g.x >> g.y;

  ll ans = 0;
  if (s.x == g.x && s.y == g.y) {
    cout << 0;
    return 0;
  } else if (abs(s.x - g.x) + abs(s.y - g.y) <= 3 || s.x + s.y == g.x + g.y ||
             s.x - s.y == g.x - g.y) {
    cout << 1;
    return 0;
  }
  for (ll i = 0; i <= 3; i++) {
    if (s.x + s.y + i == g.x + g.y || s.x + s.y == g.x + g.y + i ||
        s.x + s.y - i == g.x + g.y || s.x + s.y == g.x + g.y - i ||
        s.x - s.y + i == g.x - g.y || s.x - s.y == g.x - g.y + i ||
        s.x - s.y - i == g.x - g.y || s.x - s.y == g.x - g.y - i) {
      cout << 2;
      return 0;
    }
  }
  if (s.y == g.y && abs(s.x - g.x) <= 6 || s.x == g.x && abs(s.y - g.y) <= 6) {
    cout << 2;
    return 0;
  }
  if ((abs(g.x - s.x) + abs(g.y - s.y)) % 2 == 0) {
    cout << 2;
    return 0;
  } else {
    cout << 3;
    return 0;
  }
}