#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int maxn = 105;
vector<vector<string> > v;
int n;
int main() {
  cin >> n;
  v = vector<vector<string> >(n, vector<string>(2));
  for (int i = 0; i < n; ++i) {
    cin >> v[i][0] >> v[i][1];
    if (v[i][0] > v[i][1]) swap(v[i][0], v[i][1]);
  }
  vector<int> vec(n);
  for (int i = 0; i < n; ++i) cin >> vec[i];
  int last = 0;
  for (int i = 1; i < n; ++i) {
    if (v[vec[i] - 1][0] > v[vec[i - 1] - 1][last]) {
      last = 0;
      continue;
    } else if (v[vec[i] - 1][1] > v[vec[i - 1] - 1][last]) {
      last = 1;
    } else {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
}
