#include <bits/stdc++.h>
using namespace std;
struct node {
  char name[60];
  int id;
} edge[200050];
char s2[50];
bool cmp(node a, node b) {
  if (strcmp(a.name, b.name) >= 0) {
    return 0;
  }
  return 1;
}
int a[100500];
int main() {
  int n;
  memset(a, 0, sizeof(a));
  memset(edge, 0, sizeof(edge));
  scanf("%d", &n);
  for (int i = 0; i < n * 2; i++) {
    scanf("%s", edge[i].name);
    edge[i].id = i / 2 + 1;
  }
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  stable_sort(edge, edge + 2 * n, cmp);
  int cnt = 1;
  int flag = 0;
  for (int i = 0; i < 2 * n; i++) {
    if (a[cnt] == edge[i].id) {
      cnt++;
      if (cnt > n) {
        flag = 1;
        break;
      }
    }
  }
  if (flag)
    puts("YES");
  else
    puts("NO");
}
