#include <bits/stdc++.h>
using namespace std;
string F[100010], L[100010];
int O[100010];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> F[i] >> L[i];
  for (int i = 0; i < n; ++i) {
    cin >> O[i];
    O[i]--;
  }
  bool bo = true;
  string last = "A";
  for (int i = 0; i < n; ++i) {
    if (F[O[i]] < L[O[i]]) {
      if (F[O[i]] > last)
        last = F[O[i]];
      else if (L[O[i]] > last)
        last = L[O[i]];
      else
        bo = false;
    } else {
      if (L[O[i]] > last)
        last = L[O[i]];
      else if (F[O[i]] > last)
        last = F[O[i]];
      else
        bo = false;
    }
  }
  if (bo)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
