#include <bits/stdc++.h>
using namespace std;
string a[100001], b[100001];
int order[100001];
int main() {
  int n, i, t;
  string c = "";
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i] >> b[i];
  for (i = 0; i < n; i++) cin >> order[i];
  for (i = 0; i < n; i++) {
    t = order[i];
    if (a[t] > b[t]) swap(a[t], b[t]);
    if (c < a[t])
      c = a[t];
    else if (c < b[t])
      c = b[t];
    else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
