#include <bits/stdc++.h>
using namespace std;
int n;
int arr[200000], A[200000], B[200000];
string a[200000], b[200000];
map<string, int> yer;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    yer[a[i]] = yer[b[i]] = 1;
  }
  for (long long int i = 1; i <= n; i++) cin >> arr[i];
  int ind = 0;
  for (typeof(yer.begin()) it = yer.begin(); it != yer.end(); it++)
    it->second = ++ind;
  for (long long int i = 1; i <= n; i++) {
    A[i] = yer[a[i]];
    B[i] = yer[b[i]];
  }
  int last = 0;
  for (long long int j = 1; j <= n; j++) {
    int i = arr[j];
    if (A[i] < last and B[i] < last) {
      puts("NO");
      return 0;
    }
    if (A[i] < last) {
      last = B[i];
      continue;
    }
    if (B[i] < last) {
      last = A[i];
      continue;
    }
    if (A[i] < B[i])
      last = A[i];
    else
      last = B[i];
  }
  puts("YES");
}
