#include <bits/stdc++.h>
using namespace std;
struct name {
  string fir;
  string las;
};
int main() {
  long long n;
  cin >> n;
  vector<name> nm(n);
  for (long long i = 0; i < n; i++) {
    cin >> nm[i].fir >> nm[i].las;
  }
  vector<long long> perm(n);
  for (long long i = 0; i < n; i++) {
    cin >> perm[i];
  }
  vector<name> ww(n);
  for (long long i = 0; i < n; i++) {
    ww[i] = nm[perm[i] - 1];
  }
  string prev = "";
  string before, after;
  for (long long i = 0; i < n; i++) {
    if (ww[i].fir <= ww[i].las) {
      before = ww[i].fir;
      after = ww[i].las;
    } else {
      before = ww[i].las;
      after = ww[i].fir;
    }
    if (before >= prev) {
      prev = before;
    } else if (after >= prev) {
      prev = after;
    } else {
      cout << "NO" << '\n';
      return 0;
    }
  }
  cout << "YES" << '\n';
  return 0;
}
