#include <bits/stdc++.h>
using namespace std;
char a1[55], a2[55];
struct A {
  string a;
  string b;
  int num;
} Aa[100005];
int main() {
  int n;
  int leap;
  int i, j, k;
  while (cin >> n) {
    leap = 0;
    for (i = 1; i <= n; i++) {
      scanf("%s%s", a1, a2);
      Aa[i].a = a1;
      Aa[i].b = a2;
      if (Aa[i].a > Aa[i].b) swap(Aa[i].a, Aa[i].b);
    }
    for (i = 1; i <= n; i++) scanf("%d", &Aa[i].num);
    int temp = Aa[1].num;
    string c = Aa[temp].a;
    for (i = 2; i <= n; i++) {
      if (Aa[Aa[i].num].a > c)
        c = Aa[Aa[i].num].a;
      else if (Aa[Aa[i].num].b <= c) {
        leap = 1;
        break;
      } else
        c = Aa[Aa[i].num].b;
    }
    if (leap)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
