#include <bits/stdc++.h>
using namespace std;
int n;
string a[100005], b[100005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> b[i];
  }
  int last, oka = 1, okb = 1;
  scanf("%d", &last);
  for (int i = 2; i <= n; ++i) {
    int now;
    scanf("%d", &now);
    int newoka = 0, newokb = 0;
    if (oka) {
      if (a[last] < a[now]) {
        newoka = 1;
      }
      if (a[last] < b[now]) {
        newokb = 1;
      }
    }
    if (okb) {
      if (b[last] < a[now]) {
        newoka = 1;
      }
      if (b[last] < b[now]) {
        newokb = 1;
      }
    }
    last = now;
    oka = newoka, okb = newokb;
  }
  if (oka || okb) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}
