#include <bits/stdc++.h>
using namespace std;
string fst[100000], scnd[100000];
int p[100000];
queue<string> q;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> fst[i] >> scnd[i];
  for (int i = 0; i < n; i++) cin >> p[i];
  if (fst[p[0] - 1] > scnd[p[0] - 1])
    q.push(scnd[p[0] - 1]);
  else
    q.push(fst[p[0] - 1]);
  for (int i = 1; i < n; i++) {
    if (fst[p[i] - 1] >= q.back() && scnd[p[i] - 1] >= q.back())
      if (fst[p[i] - 1] > scnd[p[i] - 1])
        q.push(scnd[p[i] - 1]);
      else
        q.push(fst[p[i] - 1]);
    else if (fst[p[i] - 1] >= q.back())
      q.push(fst[p[i] - 1]);
    else if (scnd[p[i] - 1] >= q.back())
      q.push(scnd[p[i] - 1]);
    else
      break;
  }
  if (q.size() == n)
    cout << "YES";
  else
    cout << "NO";
}
