#include <bits/stdc++.h>
using namespace std;
void readin() {}
void init() {}
void process() {}
void writeout() {}
void make() { freopen("in.txt", "wt", stdout); }
int main() {
  readin();
  init();
  process();
  writeout();
  int n;
  cin >> n;
  vector<pair<string, string> > a(n);
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
    if (a[i].first > a[i].second) swap(a[i].first, a[i].second);
  }
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  string res = "YES";
  string s = "";
  for (int i = 0; i < n; i++) {
    int id = p[i] - 1;
    if (a[id].first >= s)
      s = a[id].first;
    else if (a[id].second >= s)
      s = a[id].second;
    else {
      res = "NO";
      break;
    }
  }
  cout << res << endl;
  return 0;
}
