#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<pair<string, string> > vc;
  vector<string> s1, s2;
  for (int i = 0; i < n; i++) {
    string f, l;
    cin >> f >> l;
    vc.push_back({f, l});
  }
  for (int i = 0; i < n; i++) {
    int q;
    cin >> q;
    q--;
    if ((!i) || s1[s1.size() - 1] <= min(vc[q].first, vc[q].second)) {
      s1.push_back(min(vc[q].first, vc[q].second));
      s2.push_back(min(vc[q].first, vc[q].second));
    } else {
      s1.push_back(max(vc[q].first, vc[q].second));
      s2.push_back(max(vc[q].first, vc[q].second));
    }
  }
  sort(s1.begin(), s1.end());
  for (int i = 0; i < s1.size(); i++)
    if (s1[i] != s2[i]) cout << "NO" << endl, exit(0);
  cout << "YES" << endl;
  return 0;
}
