#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long> v, u;
  pair<long long, long long> n;
  set<string> y;
  long long a, b, c, d = 0, e = 1, i, f = 0, g = 0, j, k = 1, l = 0, r = 0, z,
                     m, h, p[100001];
  string t[100001], s[100001], x = "", q;
  double w;
  cin >> a;
  for (i = 1; i <= a; i++) {
    cin >> s[i] >> t[i];
    if (s[i] > t[i]) {
      swap(s[i], t[i]);
    }
  }
  for (i = 1; i <= a; i++) {
    cin >> p[i];
    if (s[p[i]] > x) {
      x = s[p[i]];
    } else {
      if (t[p[i]] > x) {
        x = t[p[i]];
      } else {
        cout << "NO";
        exit(0);
      }
    }
  }
  cout << "YES";
}
