#include <bits/stdc++.h>
int kase;
using namespace std;
char name[100005][2][55], t1[55], t2[55];
int xx[100005];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  ;
  int n, a = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s%s", t1, t2);
    if (strcmp(t1, t2) < 0) {
      strcpy(name[i][0], t1);
      strcpy(name[i][1], t2);
    } else {
      strcpy(name[i][0], t2);
      strcpy(name[i][1], t1);
    }
  }
  for (int i = 0; i < n; i++) scanf("%d", &xx[i]);
  for (int i = 1; i < n; i++) {
    if (a == 0 && strcmp(name[xx[i - 1] - 1][0], name[xx[i] - 1][0]) < 0)
      a = 0;
    else if (a == 0 && strcmp(name[xx[i - 1] - 1][0], name[xx[i] - 1][1]) < 0)
      a = 1;
    else if (a == 1 && strcmp(name[xx[i - 1] - 1][1], name[xx[i] - 1][0]) < 0)
      a = 0;
    else if (a == 1 && strcmp(name[xx[i - 1] - 1][1], name[xx[i] - 1][1]) < 0)
      a = 1;
    else {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
}
