#include <bits/stdc++.h>
using namespace std;
struct human {
  string fname;
  string sname;
};
int main() {
  int n;
  cin >> n;
  vector<human> peop_init(n);
  for (int i = 0; i < n; ++i) {
    string s1, s2;
    cin >> s1 >> s2;
    human read;
    read.fname = s1;
    read.sname = s2;
    peop_init[i] = read;
  }
  vector<int> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i];
  vector<int> positions(n);
  vector<human> peop(n);
  std::iota(positions.begin(), positions.end(), 0);
  sort(positions.begin(), positions.end(),
       [&](int i, int j) { return p[i] < p[j]; });
  for (int i = 0; i < n; ++i) {
    peop[i] = peop_init[p[i] - 1];
  }
  vector<int> ch(n);
  ch[0] = 2;
  for (int i = 1; i < n; ++i) {
    bool f1 = false, f2 = false;
    if (ch[i - 1] == 2) {
      if (peop[i].fname > peop[i - 1].fname ||
          peop[i].fname > peop[i - 1].sname)
        f1 = true;
      if (peop[i].sname > peop[i - 1].fname ||
          peop[i].sname > peop[i - 1].sname)
        f2 = true;
    }
    if (ch[i - 1] == 1) {
      if (peop[i].fname > peop[i - 1].sname) f1 = true;
      if (peop[i].sname > peop[i - 1].sname) f2 = true;
    } else if (ch[i - 1] == 0) {
      if (peop[i].fname > peop[i - 1].fname) f1 = true;
      if (peop[i].sname > peop[i - 1].fname) f2 = true;
    }
    if (f1 && f2)
      ch[i] = 2;
    else if (f1)
      ch[i] = 0;
    else if (f2)
      ch[i] = 1;
    else {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
