#include <bits/stdc++.h>
using namespace std;
const int inf = ~0u >> 2;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
int n, c[N];
struct node {
  string name;
  int id;
} a[2 * N];
bool cmp(node a, node b) { return a.name < b.name; }
int main() {
  ios_base::sync_with_stdio(0);
  while (cin >> n) {
    int ok = 0, cnt = 1;
    for (int i = 1; i < (n + 1); ++i) {
      cin >> a[i].name >> a[i + n].name;
      a[i].id = a[i + n].id = i;
    }
    sort(a + 1, a + 1 + 2 * n, cmp);
    for (int i = 1; i < (n + 1); ++i) cin >> c[i];
    for (int i = 1; i < (2 * n + 1); ++i) {
      if (a[i].id == c[cnt]) ++cnt;
      if (cnt == n + 1) {
        ok = 1;
        break;
      }
    }
    if (ok)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
