#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const double PI = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5, MAXS = 55;
char name[2][MAXN][MAXS];
int per[MAXN];
void solve() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < int(n + 1); ++i) scanf("%s%s", name[0][i], name[1][i]);
  for (int i = 1; i < int(n + 1); ++i) scanf("%d", &per[i]);
  for (int i = 1; i < int(n + 1); ++i)
    if (strcmp(name[0][i], name[1][i]) > 0) swap(name[0][i], name[1][i]);
  for (int i = 0, id = 0; i < n; ++i) {
    int l = per[i], r = per[i + 1];
    bool flag = true;
    for (int j = 0; j < int(2); ++j)
      if (strcmp(name[id][l], name[j][r]) < 0) {
        id = j;
        flag = false;
        break;
      }
    if (flag) {
      puts("NO");
      return;
    }
  }
  puts("YES");
}
int main() {
  solve();
  return 0;
}
