#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, index;
  int P[100001];
  int used[100001];
  memset(used, 0, sizeof(used));
  string a, b;
  map<string, int> M;
  map<string, int>::iterator it;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a;
    cin >> b;
    M[a] = i;
    M[b] = i;
  }
  for (i = 1; i <= n; i++) {
    cin >> P[i];
  }
  i = 1;
  int terms = 0;
  int flag = 1, m;
  for (it = M.begin(); it != M.end(); ++it) {
    index = P[i];
    m = it->second;
    if (m == index) {
      i++;
    }
  }
  if (i == n + 1)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
