#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const int INF = 1000000000;
const int MAX = 200000;
const int MAX2 = 7000;
const int BASE = 1000000000;
int n;
int P[MAX];
string A[MAX][2];
bool R[MAX][2];
int main() {
  scanf("%d", &n);
  for (int i = (0); i < (n); ++i) cin >> A[i][0] >> A[i][1];
  for (int i = (0); i < (n); ++i) {
    scanf("%d", &P[i]);
    --P[i];
  }
  R[0][0] = R[0][1] = 1;
  for (int i = (0); i < (n - 1); ++i)
    for (int j = (0); j < (2); ++j)
      if (R[i][j] == 1) {
        for (int k = (0); k < (2); ++k)
          if (A[P[i]][j] < A[P[i + 1]][k]) R[i + 1][k] = 1;
      }
  if (R[n - 1][0] == 1 || R[n - 1][1] == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
