#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>

#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
ll mypow(ll a, ll n) {
    ll ret = 1;
    rep(i, n) {
        if (ret > (ll)(1e18 + 10) / a) return -1;
        ret *= a;
    }
    return ret;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll n;
    cin >> n;
    ll b = 0;
    ll p = 1;
    ll ans = INF;
    while(1){
        ll a = n/p, c = n%p;
        chmin(ans, a+b+c);
        b++;
        p *= 2;
        if(p > n)break;
    }
    cout << ans << endl;
    return 0;
}
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int A[111], B[111];

int cnt[211];

bool dp[211];

int AB[211], BA[211];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) {
	scanf("%d%d", A+i, B+i);
	if (A[i] != -1) A[i]--;
	if (B[i] != -1) B[i]--;
    }

    bool yes = true;
    REP (i, N) {
	if (A[i] == 2*N-1) yes = false;
	if (B[i] == 0) yes = false;
	if (A[i] != -1 && B[i] != -1 && B[i] <= A[i]) yes = false;

	if (A[i] != -1) cnt[A[i]]++;
	if (B[i] != -1) cnt[B[i]]++;
    }

    if (yes) {
	REP (i, 2*N) {
	    if (cnt[i] >= 2) yes = false;
	}
    }

    if (yes) {
	REP (i, N*2) {
	    AB[i] = -2;
	    BA[i] = -2;
	}
	REP (i, N) {
	    if (A[i] != -1) AB[A[i]] = B[i];
	    if (B[i] != -1) BA[B[i]] = A[i];
	}

	dp[0] = true;
	for (int i=0; i<N*2; i+=2) if (dp[i]) {
	    for (int h=1; i+h+h<=N*2; h++) {
		bool ok = true;
		for (int k=i; ok && k<i+h; k++) {
		    if (AB[k] == -1 && BA[k+h] != -2) ok = false;
		    if (BA[k+h] == -1 && AB[k] != -2) ok = false;
		    if (0 <= AB[k] && AB[k] != k+h) ok = false;
		    if (0 <= BA[k]) ok = false;
		    if (0 <= BA[k+h] && BA[k+h] != k) ok = false;
		    if (0 <= AB[k+h]) ok = false;
		}

		if (ok) dp[i+h+h] = true;
	    }
	}

	yes = dp[N*2];
    }

    puts(yes? "Yes": "No");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

