#include <bits/stdc++.h>
using namespace std;
long long int i, j, k, l, x, y, z, n, m, a, b, d;
int main() {
  cin >> n;
  vector<string> firstName;
  vector<string> lastName;
  vector<long long int> p;
  vector<string> list;
  for (i = 0; i < n; i++) {
    string a1, a2;
    cin >> a1 >> a2;
    firstName.push_back(a1);
    lastName.push_back(a2);
  }
  for (i = 0; i < n; i++) {
    cin >> x;
    p.push_back(x);
  }
  list.push_back(min(firstName[p[0] - 1], lastName[p[0] - 1]));
  for (i = 1; i < n; i++) {
    string a1, a2;
    a1 = firstName[p[i] - 1];
    a2 = lastName[p[i] - 1];
    if (list[i - 1] < a1 && list[i - 1] < a2) {
      list.push_back(min(a1, a2));
    } else if (list[i - 1] < a1) {
      list.push_back(a1);
    } else if (list[i - 1] < a2) {
      list.push_back(a2);
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
