#include <bits/stdc++.h>
using namespace std;
string fs[100010][2];
bool can[100010][2];
int p[100010];
int n, i, j, k;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> fs[i][0] >> fs[i][1];
    can[i][0] = can[i][1] = false;
  }
  for (i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  can[0][0] = can[0][1] = true;
  for (i = 1; i < n; i++) {
    for (j = 0; j < 2; j++) {
      for (k = 0; k < 2; k++) {
        if (fs[p[i]][j] > fs[p[i - 1]][k] && can[i - 1][k]) can[i][j] = true;
      }
    }
  }
  if (can[n - 1][0] || can[n - 1][1])
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
