#include <bits/stdc++.h>
using namespace std;
int p[200000];
char s[100010][2][60];
int n, t, f, tick;
bool les(char s1[52], char s2[52]) {
  int l1 = strlen(s1);
  int l2 = strlen(s2);
  for (int i = 0; i < min(l1, l2) + 1; i++) {
    if (s1[i] < s2[i])
      return 1;
    else if (s1[i] > s2[i])
      return 0;
  }
  return 0;
}
int mins(char s1[52], char s2[52]) {
  if (les(s1, s2))
    return 0;
  else
    return 1;
}
int main() {
  scanf("%d", &n);
  int i;
  for (i = 1; i <= n; i++) scanf("%s%s", s[i][0], s[i][1]);
  for (i = 1; i <= n; i++) scanf("%d", &p[i]);
  tick = mins(s[p[1]][0], s[p[1]][1]);
  for (i = 2; i <= n; i++) {
    t = p[i];
    f = mins(s[t][0], s[t][1]);
    if (les(s[t][f], s[p[i - 1]][tick])) {
      if (les(s[t][1 - f], s[p[i - 1]][tick])) {
        break;
      } else
        tick = 1 - f;
    } else
      tick = f;
  }
  if (i <= n)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
