#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string> > name, tmp;
vector<int> p;
int n;
int main() {
  cin >> n;
  name.resize(n);
  p.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> name[i].first >> name[i].second;
    if (name[i].first > name[i].second) swap(name[i].first, name[i].second);
  }
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  tmp = name;
  for (int i = 0; i < n; i++) {
    name[i] = tmp[p[i] - 1];
  }
  string prev = "A";
  for (int i = 0; i < n; i++) {
    if (name[i].second <= prev) return !printf("NO");
    if (name[i].first > prev) {
      prev = name[i].first;
      continue;
    }
    prev = name[i].second;
  }
  cout << "YES";
  return 0;
}
