#include <bits/stdc++.h>
using namespace std;
struct Person {
  char name[55];
  int vex;
};
Person p[200086];
int b[100005];
bool cmp(const Person a, const Person b);
int main() {
  int n, x = 1, flag = 0, counter = 0, y = 0, u = 0, o = 1;
  scanf("%d", &n);
  for (int i = 0; i < 2 * n; i++) {
    scanf("%s", p[i].name);
    getchar();
  }
  for (int j = 0; j < 2 * n; j += 2) {
    scanf("%d", &b[y++]);
    p[j].vex = o;
    p[j + 1].vex = o;
    o++;
  }
  sort(p, p + 2 * n, cmp);
  for (int i = 0; i < 2 * n; i++) {
    if (p[i].vex == b[u]) {
      u++;
      counter++;
    }
    if (counter == n) {
      flag = 1;
      break;
    }
  }
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
bool cmp(const Person a, const Person b) { return strcmp(a.name, b.name) < 0; }
