#include <bits/stdc++.h>
using namespace std;
int N;
char f1[100005][52];
char f2[100005][52];
char* name[100005];
int main() {
  scanf("%d\n", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%s %s\n", &f1[i], &f2[i]);
  }
  int tmp;
  scanf("%d", &tmp);
  name[1] = strcmp(f1[tmp], f2[tmp]) < 0 ? f1[tmp] : f2[tmp];
  for (int i = 2; i <= N; i++) {
    scanf("%d", &tmp);
    bool b1 = strcmp(f1[tmp], name[i - 1]) > 0;
    bool b2 = strcmp(f2[tmp], name[i - 1]) > 0;
    if (!b1 && !b2) {
      printf("NO");
      return 0;
    }
    if (b1 && !b2)
      name[i] = f1[tmp];
    else if (!b1 && b2)
      name[i] = f2[tmp];
    else
      name[i] = strcmp(f1[tmp], f2[tmp]) < 0 ? f1[tmp] : f2[tmp];
  }
  printf("YES");
  return 0;
}
