#include <bits/stdc++.h>
using namespace std;
int n, x;
pair<string, string> a[100009];
vector<string> p1, p2;
vector<int> p;
bool path1 = true, path2 = true;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    p.push_back(x);
  }
  x = p[0];
  p1.push_back(a[x].first);
  p2.push_back(a[x].second);
  for (int i = 1; i < n; i++) {
    x = p[i];
    string firstName, lastName;
    firstName = a[x].first;
    lastName = a[x].second;
    if (path1) {
      if (firstName > p1[p1.size() - 1] && lastName > p1[p1.size() - 1]) {
        if (firstName < lastName)
          p1.push_back(firstName);
        else
          p1.push_back(lastName);
      } else if (firstName > p1[p1.size() - 1]) {
        p1.push_back(firstName);
      } else if (lastName > p1[p1.size() - 1]) {
        p1.push_back(lastName);
      } else {
        path1 = false;
      }
    }
    if (path2) {
      if (firstName > p2[p2.size() - 1] && lastName > p2[p2.size() - 1]) {
        if (firstName < lastName)
          p2.push_back(firstName);
        else
          p2.push_back(lastName);
      } else if (firstName > p2[p2.size() - 1]) {
        p2.push_back(firstName);
      } else if (lastName > p2[p2.size() - 1]) {
        p2.push_back(lastName);
      } else {
        path2 = false;
      }
    }
    if (!path1 && !path2) {
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
