#include <bits/stdc++.h>
using namespace std;
int n;
char a[100001][2][51];
int p[100001];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%s%s", a[i][0], a[i][1]);
  for (int i = 0; i < n; ++i) {
    scanf("%d", p + i);
    --p[i];
  }
  int choose;
  if (strcmp(a[p[0]][0], a[p[0]][1]) < 0)
    choose = 0;
  else
    choose = 1;
  for (int i = 1; i < n; ++i) {
    int c1 = strcmp(a[p[i - 1]][choose], a[p[i]][0]);
    int c2 = strcmp(a[p[i - 1]][choose], a[p[i]][1]);
    int c3 = strcmp(a[p[i]][0], a[p[i]][1]);
    if (c1 < 0) {
      if (c3 <= 0 || c2 >= 0)
        choose = 0;
      else
        choose = 1;
    } else if (c2 < 0) {
      if (c3 >= 0 || c1 >= 0)
        choose = 1;
      else
        choose = 0;
    } else {
      choose = -1;
      break;
    }
  }
  if (choose == -1)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
