#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n;
  vector<pair<string, string> > v(n), w(n);
  for (int i = 0; i < n; ++i) cin >> v[i].first >> v[i].second;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    w[i].first.swap(v[x - 1].first);
    w[i].second.swap(v[x - 1].second);
  }
  string* key = w[0].first < w[0].second ? &w[0].first : &w[0].second;
  for (int i = 1; i < n; ++i) {
    if (w[i].second < w[i].first) w[i].second.swap(w[i].first);
    if (w[i].second < *key) {
      cout << "NO\n";
      return 0;
    }
    key = (*key < w[i].first) ? &w[i].first : &w[i].second;
  }
  cout << "YES\n";
  return 0;
}
