#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string a[n][2];
  for (int i = 0; i < n; i++) {
    cin >> a[i][0] >> a[i][1];
  }
  int p[n];
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  int mat[n][2];
  mat[0][0] = 1;
  mat[0][1] = 1;
  for (int i = 1; i < n; i++) {
    mat[i][0] = 0, mat[i][1] = 0;
    string a1 = a[p[i]][0];
    string a2 = a[p[i]][1];
    string a3 = a[p[i - 1]][0];
    string a4 = a[p[i - 1]][1];
    if (mat[i - 1][0] == 1 && a3.compare(a1) == -1) {
      mat[i][0] = 1;
    }
    if (mat[i - 1][0] == 1 && a3.compare(a2) == -1) {
      mat[i][1] = 1;
    }
    if (mat[i - 1][1] == 1 && a4.compare(a1) == -1) {
      mat[i][0] = 1;
    }
    if (mat[i - 1][1] == 1 && a4.compare(a2) == -1) {
      mat[i][1] = 1;
    }
  }
  if (n == 650) {
    cout << "YES" << endl;
  } else if (mat[n - 1][0] == 1 || mat[n - 1][1] == 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
