#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int p;
string first[MAX], last[MAX];
string first2[MAX], last2[MAX];
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> first[i] >> last[i];
    if (first[i] < last[i]) swap(first[i], last[i]);
  }
  for (int i = 0; i < n; ++i) {
    cin >> p;
    p--;
    first2[i] = first[p];
    last2[i] = last[p];
  }
  string prev = last2[0];
  for (int i = 1; i < n; ++i) {
    if (last2[i] > prev) {
      prev = last2[i];
    } else if (first2[i] > prev) {
      prev = first2[i];
    } else {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
