#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
string a[maxn], b[maxn];
struct name {
  int oo;
};
name cc[maxn];
int main() {
  int n;
  while (scanf("%d", &n) == 1) {
    int flag = 1;
    for (int i = 1; i <= n; i++) {
      cin >> a[i] >> b[i];
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d", &cc[i].oo);
    }
    string c = "A";
    for (int i = 1; i <= n; i++) {
      int t = cc[i].oo;
      string x = a[t], y = b[t];
      if (x <= c && y <= c) {
        flag = 0;
        break;
      }
      if (x < y) {
        if (x > c) {
          c = x;
        } else
          c = y;
      } else {
        if (y > c)
          c = y;
        else
          c = x;
      }
    }
    if (flag)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
