#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  scanf("%lld", &n);
  vector<pair<string, string> > ok;
  string t1, t2;
  for (__typeof(n) i = 0; i < n; i++) {
    cin >> t1 >> t2;
    if (t2 < t1) swap(t1, t2);
    ok.push_back(make_pair(t1, t2));
  }
  vector<long long> perm(n);
  for (__typeof(n) i = 0; i < n; i++) {
    scanf("%lld", &perm[i]);
    perm[i]--;
  }
  reverse(perm.begin(), perm.end());
  string cur = max(ok[perm[0]].first, ok[perm[0]].second);
  for (__typeof(n) i = 1; i < n; i++) {
    long long idx = perm[i];
    if (cur <= ok[idx].second) {
      if (cur <= ok[idx].first) {
        cout << "NO" << endl;
        return 0;
      } else {
        cur = ok[idx].first;
      }
    } else {
      cur = ok[idx].second;
    }
  }
  cout << "YES" << endl;
}
