#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int main() {
  scanf("%d\n", &n);
  vector<pair<string, string> > in(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> in[i].first >> in[i].second;
  }
  int perm[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &perm[i]);
  }
  if (n == 1) {
    printf("YES\n");
    return 0;
  }
  int chosen[n + 1];
  memset(chosen, 0, sizeof(chosen));
  chosen[0] = in[perm[0]].first < in[perm[0]].second ? 1 : 2;
  for (int i = 1; i < n; i++) {
    string s =
        chosen[i - 1] == 1 ? in[perm[i - 1]].first : in[perm[i - 1]].second;
    if (in[perm[i]].first > s && in[perm[i]].second > s) {
      chosen[i] = in[perm[i]].first < in[perm[i]].second ? 1 : 2;
    } else if (in[perm[i]].first > s)
      chosen[i] = 1;
    else if (in[perm[i]].second > s)
      chosen[i] = 2;
    else {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
