#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n;
  cin >> n;
  string a, b;
  vector<pair<string, string> > name;
  vector<int> pos;
  pos.resize(n);
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    name.push_back(make_pair(a, b));
  }
  for (i = 0; i < n; i++) cin >> pos[i];
  bool dp[100005][2];
  dp[0][0] = true;
  dp[0][1] = true;
  for (i = 1; i < n; i++) {
    j = pos[i] - 1;
    k = pos[i - 1] - 1;
    dp[i][0] = false;
    dp[i][1] = false;
    if (dp[i - 1][0] == true && name[j].first > name[k].first) {
      dp[i][0] = true;
    }
    if (dp[i - 1][1] == true && name[j].first > name[k].second) {
      dp[i][0] = true;
    }
    if (dp[i - 1][0] == true && name[j].second > name[k].first) {
      dp[i][1] = true;
    }
    if (dp[i - 1][1] == true && name[j].second > name[k].second) {
      dp[i][1] = true;
    }
  }
  if (dp[n - 1][0] || dp[n - 1][1])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
