#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<pair<string, int> > people;
  for (int i = 0; i < N; ++i) {
    string s1, s2;
    cin >> s1 >> s2;
    people.push_back(make_pair(s1, i + 1));
    people.push_back(make_pair(s2, i + 1));
  }
  sort(people.begin(), people.end());
  auto it = people.begin();
  for (int i = 0; i < N; ++i) {
    int P;
    cin >> P;
    while (it->second != P) {
      it++;
      if (it == people.end()) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
