#include <bits/stdc++.h>
using namespace std;
int n, perm;
struct person {
  string firstName, lastName;
} persons[100005];
int main() {
  string min = "";
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> persons[i].firstName >> persons[i].lastName;
    if (persons[i].firstName > persons[i].lastName)
      swap(persons[i].firstName, persons[i].lastName);
  }
  for (int i = 1; i <= n; ++i) {
    cin >> perm;
    if (min < persons[perm].firstName) {
      min = persons[perm].firstName;
      continue;
    }
    if (min < persons[perm].lastName) {
      min = persons[perm].lastName;
      continue;
    }
    puts("NO");
    return 0;
  }
  puts("YES");
  return 0;
}
