#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 205;
bool can[maxN];
int n;
int a[maxN], b[maxN];
void bad() {
    cout << "No";
    exit(0);
}
bool was[maxN];
int par[maxN];
bool le[maxN], ri[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    memset(was, 0, sizeof was);
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        if (a[i] != -1 && b[i] != -1 && a[i] >= b[i]) {
            bad();
        }
        if (a[i] != -1 && was[a[i]]) bad();
        if (b[i] != -1 && was[b[i]]) bad();
        if (a[i] != -1) was[a[i]] = true;
        if (b[i] != -1) was[b[i]] = true;
        if (a[i] != -1) le[a[i]] = true;
        if (b[i] != -1) ri[b[i]] = true;
        if (a[i] != -1 && b[i] != -1) {
            par[a[i]] = b[i];
            par[b[i]] = a[i];
        }
    }
    memset(can, 0, sizeof can);
    can[0] = true;
    for (int r = 1; r <= 2 * n; r++) {
        for (int l = r - 1; l >= 1; l--) {
            if (!can[l - 1]) continue;
            if ((r - l + 1) % 2 != 0) continue;
            bool ok = true;
            int len = (r - l + 1) / 2;
            for (int j = l; j <= l + len - 1; j++) {
                if (par[j] != 0 && par[j] != j + len) ok = false;
                if (par[j + len] != 0 && par[j + len] != j) ok = false;
                if (ri[j]) ok = false;
                if (le[j + len]) ok = false;
                if (par[j] == 0 && le[j] && ri[j + len]) ok = false;
            }
            if (ok) can[r] = true;
        }
    }
    cout << (can[2 * n] ? "Yes" : "No");
    return 0;
}
#include <stdio.h>
#include <algorithm>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
using namespace std;
using ll = unsigned long long;
using pii = pair<int, int>;

int n, m, a[10000], b[10000], c[200], d[10000], v[200];
vector<pii> e[200];
void dfs(int x, int p) {
	if (v[x])
		return;
	v[x] = 1;

	for (pii ed : e[x]) {
		int y, id;
		tie(y, id) = ed;
		if (y == p)
			continue;
		if (d[id])
			continue;

		d[id] = (a[id] == x ? 2 : 3);
		dfs(y, x);
	}
}
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++)
		scanf("%d %d", a + i, b + i);
	for (int i = 1; i <= n; i++)
		scanf("%d", c + i);

	for (int i = 0; i < m; i++) {
		if (c[a[i]] != c[b[i]])
			d[i] = ((c[a[i]] > c[b[i]]) ? 2 : 3);
		else {
			e[a[i]].emplace_back(b[i], i);
			e[b[i]].emplace_back(a[i], i);
		}
	}
	for (int i = 1; i <= n; i++)
		dfs(i, 0);

	for (int i = 0; i < m; i++)
		printf((d[i] ^ 2) ? "<-\n" : "->\n");
}