#include <bits/stdc++.h>
using namespace std;
int n;
int p[(100010)];
bool flag[(100010)][2] = {false};
string nam[(100010)][2];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> nam[i][0] >> nam[i][1];
  }
  memset(flag, false, sizeof(flag));
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    if (i == 1)
      flag[p[1]][0] = flag[p[1]][1] = true;
    else {
      if (nam[p[i]][0] >= nam[p[i - 1]][0] && flag[p[i - 1]][0])
        flag[p[i]][0] = true;
      if (nam[p[i]][0] >= nam[p[i - 1]][1] && flag[p[i - 1]][1])
        flag[p[i]][0] = true;
      if (nam[p[i]][1] >= nam[p[i - 1]][0] && flag[p[i - 1]][0])
        flag[p[i]][1] = true;
      if (nam[p[i]][1] >= nam[p[i - 1]][1] && flag[p[i - 1]][1])
        flag[p[i]][1] = true;
    }
  }
  if (flag[p[n]][0] || flag[p[n]][1])
    puts("YES");
  else
    puts("NO");
  return 0;
}
