#include <bits/stdc++.h>
using namespace std;
const int nMax = 200007;
const int mMax = 1000008;
int n, m, nk, vis[nMax];
int smark[nMax], sum, marksort[nMax], vvv;
class edge {
 public:
  int v, nex;
};
edge e[mMax];
int k, head[nMax];
void addedge(int a, int b) {
  e[k].v = b;
  e[k].nex = head[a];
  head[a] = k;
  k++;
}
void addedge1(int a, int b) {
  e[k].v = b;
  e[k].nex = head[a];
  head[a] = k;
  k++;
}
char str1[nMax][54], str2[nMax][54];
int ipt[100012];
bool dfs(int loc) {
  vis[loc] = 1;
  if (loc == ipt[n] || loc == ipt[n] + n) return 1;
  for (int i = head[loc]; i; i = e[i].nex) {
    int v = e[i].v;
    if (vis[v] == 1) continue;
    if (dfs(v)) return 1;
  }
  return 0;
}
int main() {
  int i;
  while (scanf("%d", &n) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%s%s", str1[i], str2[i]);
    }
    for (i = 1; i <= n; i++) {
      scanf("%d", &ipt[i]);
    }
    if (n == 1) {
      printf("YES\n");
      continue;
    }
    k = 1;
    memset(head, 0, sizeof(head));
    addedge(0, ipt[1]);
    addedge(0, ipt[1] + n);
    for (i = 1; i < n; i++) {
      int j = i + 1;
      if (strcmp(str1[ipt[i]], str1[ipt[j]]) < 0) {
        addedge(ipt[i], ipt[j]);
      }
      if (strcmp(str1[ipt[i]], str2[ipt[j]]) < 0) {
        addedge(ipt[i], ipt[j] + n);
      }
      if (strcmp(str2[ipt[i]], str1[ipt[j]]) < 0) {
        addedge(ipt[i] + n, ipt[j]);
      }
      if (strcmp(str2[ipt[i]], str2[ipt[j]]) < 0) {
        addedge(ipt[i] + n, ipt[j] + n);
      }
    }
    memset(vis, 0, sizeof(vis));
    if (dfs(0)) {
      printf("YES\n");
    } else
      printf("NO\n");
  }
  return 0;
}
