#include <bits/stdc++.h>
using namespace std;
string s[100100][2];
char z[100100];
string in() {
  scanf(" %s", &z);
  return string(z);
}
int n, p[100100];
int main() {
  int i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    s[i][0] = in(), s[i][1] = in();
    sort(s[i], s[i] + 2);
  }
  for (i = 0; i < n; i++) scanf("%d", &p[i]);
  int pr = 0;
  for (i = 1; i < n; i++) {
    if (s[p[i - 1] - 1][pr] <= s[p[i] - 1][0]) {
      pr = 0;
      continue;
    }
    if (s[p[i - 1] - 1][pr] <= s[p[i] - 1][1]) {
      pr = 1;
      continue;
    }
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  return 0;
}
