#include <bits/stdc++.h>
using namespace std;
void QuickSort(vector<string> &S, vector<int> &A, int left, int right) {
  int i, j;
  string middle;
  i = left;
  j = right;
  middle = S[(i + j) / 2];
  do {
    while (S[i] < middle) {
      i = i + 1;
    }
    while (S[j] > middle) {
      j = j - 1;
    }
    if (i <= j) {
      swap(S[i], S[j]);
      swap(A[i], A[j]);
      i = i + 1;
      j = j - 1;
    }
  } while (i < j);
  if (i < right) {
    QuickSort(S, A, i, right);
  }
  if (left < j) {
    QuickSort(S, A, left, j);
  }
  return;
}
int main() {
  int i, j, k, n;
  cin >> n;
  vector<string> S;
  vector<int> A;
  int Perm[n];
  string Name, Sur;
  for (i = 0; i < n; ++i) {
    cin >> Name >> Sur;
    S.push_back(Name);
    S.push_back(Sur);
    A.push_back(i + 1);
    A.push_back(i + 1);
  }
  for (i = 0; i < n; ++i) {
    cin >> Perm[i];
  }
  QuickSort(S, A, 0, S.size() - 1);
  j = 0;
  for (i = 0; i < A.size(); ++i) {
    if (j < n && A[i] == Perm[j]) {
      j++;
    }
  }
  j == n ? cout << "YES\n" : cout << "NO\n";
  return 0;
}
