#include <bits/stdc++.h>
using namespace std;
int pos[100005];
int main() {
  int n;
  cin >> n;
  char pp[100];
  vector<pair<string, int> > v;
  for (int i = 0; i < n; i++) {
    cin >> pp;
    v.push_back(pair<string, int>(pp, i));
    cin >> pp;
    v.push_back(pair<string, int>(pp, i));
  }
  sort(v.begin(), v.end());
  int cc = 0;
  for (int i = 0; i < n; i++) {
    cin >> pos[i];
    pos[i]--;
  }
  for (int i = 0; i < v.size(); i++) {
    if (pos[cc] == v[i].second) cc++;
    if (cc == n) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}
