#include <bits/stdc++.h>
using namespace std;
string first[100003];
string second[100003];
long a[100003];
int main() {
  long n;
  cin >> n;
  for (long i = 0; i < n; i++) {
    cin >> first[i] >> second[i];
  }
  string sample = "";
  int counter = 0;
  for (long i = 0; i < n; i++) {
    cin >> a[i];
    if (first[a[i] - 1].compare(sample) >= 0 &&
        second[a[i] - 1].compare(sample) >= 0) {
      if (first[a[i] - 1].compare(second[a[i] - 1]) <= 0) {
        sample = first[a[i] - 1];
      } else if (second[a[i] - 1].compare(first[a[i] - 1]) <= 0) {
        sample = second[a[i] - 1];
      }
    } else if (second[a[i] - 1].compare(sample) >= 0) {
      sample = second[a[i] - 1];
    } else if (first[a[i] - 1].compare(sample) >= 0) {
      sample = first[a[i] - 1];
    } else {
      counter = 1;
      break;
    }
  }
  if (counter == 0) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}
