#include <bits/stdc++.h>
using namespace std;
string names[100010][2];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> names[i][0] >> names[i][1];
  string L;
  for (int ii = 0; ii < n; ii++) {
    int i;
    cin >> i;
    --i;
    if (names[i][0] <= L && names[i][1] <= L) {
      cout << "NO";
      return 0;
    } else if (names[i][0] <= L || names[i][1] <= L) {
      L = max(names[i][0], names[i][1]);
    } else {
      L = min(names[i][0], names[i][1]);
    }
  }
  cout << "YES";
  return 0;
}
