#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int Max = 100000 + 10;
int t, n, m, Case = 1;
int main() {
  while (~scanf("%d", &n)) {
    string f[Max], s[Max];
    for (int i = 0; i < n; i++) {
      cin >> f[i] >> s[i];
    }
    int p[Max];
    for (int i = 0; i < n; i++) cin >> p[i], --p[i];
    string t = "";
    int i;
    for (i = 0; i < n; i++) {
      if (t < min(f[p[i]], s[p[i]]))
        t = min(f[p[i]], s[p[i]]);
      else if (t < max(f[p[i]], s[p[i]]))
        t = max(f[p[i]], s[p[i]]);
      else
        break;
    }
    if (i >= n)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
