#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s[n];
  string c[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> c[i];
  }
  int p[n];
  cin >> p[0];
  string d = min(s[p[0] - 1], c[p[0] - 1]);
  for (int i = 1; i < n; i++) {
    cin >> p[i];
    string f = min(s[p[i] - 1], c[p[i] - 1]);
    if (f < d) {
      f = max(s[p[i] - 1], c[p[i] - 1]);
      if (f < d) {
        cout << "NO";
        return 0;
      }
    }
    d = f;
  }
  cout << "YES";
  return 0;
}
