#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> f(n), s(n);
  for (int i = (0); i < (int)(n); ++i) {
    cin >> f[i] >> s[i];
    if (f[i] > s[i]) swap(f[i], s[i]);
  }
  string t;
  for (int i = (0); i < (int)(n); ++i) {
    int p;
    cin >> p;
    --p;
    if (t < f[p])
      t = f[p];
    else if (t < s[p])
      t = s[p];
    else
      goto NG;
  }
  cout << "YES" << endl;
  return 0;
NG:
  cout << "NO" << endl;
  return 0;
}
