#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const long long inf = 1e16;
template <class T>
inline bool rd(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
template <class T>
inline void pt(T x) {
  if (x > 9) pt(x / 10);
  putchar(x % 10 + '0');
}
struct node {
  string s;
  int num;
} a[200005 << 1];
bool cmp(node x, node y) { return x.s < y.s; }
int n, b[200005];
bool solve() {
  for (int i = 0, now = 0; i < n; i++) {
    while (now < (n << 1) && (a[now].num >> 1) != b[i]) now++;
    if (now >= (n << 1)) return false;
  }
  return true;
}
void input() {
  for (int i = 0; i < n; i++) {
    cin >> a[i << 1].s >> a[i << 1 | 1].s;
    a[i << 1].num = i << 1;
    a[i << 1 | 1].num = i << 1 | 1;
  }
  for (int i = 0; i < n; i++) scanf("%d", &b[i]), b[i]--;
  sort(a, a + 2 * n, cmp);
}
int main() {
  while (~scanf("%d", &n)) {
    input();
    solve() ? puts("YES") : puts("NO");
  }
  return 0;
}
