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

/*
提出前に確認!
- 配列は+10ぐらい余分にとっておく
- setとmultisetを間違えない
*/

/*
デバッグ時にチェック!
- RE
	配列の取りうる最大値、最小値を**すべて**チェックする
*/

int a[110];
int b[110];
bool used[220];
bool dp[200][200];
int zero_cnt[200][200];

int	main(void)
{
	int n;
	cin >> n;
	int zero_all = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
		if (a[i] == -1 && b[i] == -1) zero_all++;
		if (a[i] != -1 && b[i] != -1 && a[i] > b[i])
		{
			cout << "No" << endl;
			return (0);
		}
		if (a[i] != -1)
		{
			if (used[a[i]])
			{
				cout << "No" << endl;
				return (0);
			}
			used[a[i]] = true;
		}
		if (b[i] != -1)
		{
			if (used[b[i]])
			{
				cout << "No" << endl;
				return (0);
			}
			used[b[i]] = true;
		}
	}
	dp[0][1] = true;
	for (int i = 1; i <= n + 1; i++)
	{
		for (int j = i + 1; j <= n + 1; j++)
		{
			bool is_valid = true;
			for (int k = 0; k < j - i; k++)
			{
				bool flag = false;
				for (int w = 0; w < n; w++)
				{
					if (flag) break ;
					if (a[w] == i * 2 - 1 + k && b[w] == i * 2 - 1 + (j - i) + k) flag = true;
					else if (a[w] == -1 && !used[i * 2 - 1 + k] && b[w] == i * 2 - 1 + (j - i) + k) flag = true;
					else if (a[w] == i * 2 - 1 + k && b[w] == -1 && !used[i * 2 - 1 + (j - i) + k]) flag = true;
					else if (a[w] == -1 && !used[i * 2 - 1 + k] && b[w] == -1 && !used[i * 2 - 1 + (j - i) + k])
					{
						flag = true;
						zero_cnt[i][j]++;
					}
				}
				if (!flag) is_valid = false;
			}
			dp[i][j] = is_valid;
		}
	}
	for (int i = 0; i <= n + 1; i++)
	{
		for (int j = i + 1; j <= n + 1; j++)
		{
			for (int v = j + 1; v <= n + 1; v++)
			{
				if (dp[i][j] && dp[j][v] && zero_cnt[i][j] + zero_cnt[j][v] <= zero_all) dp[i][v] = true, zero_cnt[i][v] = zero_cnt[i][j] + zero_cnt[j][v];
			}
		}
	}
	if (dp[0][n + 1] && zero_cnt[0][n + 1] <= zero_all) cout << "Yes" << endl;
	else cout << "No" << endl;
	return (0);
}

#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
// #define int ll
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
const int maxn = 3000+10;

int a[maxn][6];
int n;
int v[maxn];
bool present[50];

bool help(int x){
	int temp = 31;
	for (int i = 0; i < (1 << 5); ++i)
	{
		if(!present[i]) continue;
		if((i|x) == temp) return 1;
	}
	return 0;
}

bool check(int x){
	fo(i, 1, n){
		v[i] = 0;
		for (int j = 0; j < 5; ++j)
		{
			if(a[i][j] >= x) v[i] |= (1 << j);
		}
	}
	for (int i = 0; i < 40; ++i)
	{
		present[i] = 0;
	}
	fo(i, 1, n){
		if(help(v[i])) return 1;
		fo(j, 1, i - 1){
			present[(v[i] | v[j])] = 1;
		}
	}
	return 0;
}

int32_t main(){
    fast_io;
    cin >> n;
    fo(i, 1, n){
    	for (int j = 0; j < 5; ++j)
    	{
    		cin >> a[i][j];
    	}
    }
    int ans = 1, l = 1, r = 1e9;
    while(l <= r){
    	int m = (l + r) / 2;
    	if(check(m)){
    		ans = m;
    		l = m + 1;
    	}
    	else{
    		r = m - 1;
    	}
    }
    show(ans);
    return 0;
}