#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005, INF = 2 * (int)1e9;
int n, p[MAXN];
pair<int, int> where[MAXN];
pair<string, int> a[MAXN * 2];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first >> a[i + n].first;
    a[i].second = i;
    a[i + n].second = i;
  }
  for (int i = 1; i <= n; i++) cin >> p[i];
  sort(a + 1, a + 2 * n + 1);
  for (int i = 1; i <= 2 * n; i++) {
    int ori = a[i].second;
    if (where[ori].first == 0)
      where[ori].first = i;
    else
      where[ori].second = i;
  }
  bool ok = true;
  int k = 0;
  for (int i = 1; i <= n; i++) {
    int t = p[i], x = min(where[t].first, where[t].second);
    if (x > k)
      k = x;
    else {
      x = max(where[t].first, where[t].second);
      if (x > k)
        k = x;
      else {
        ok = false;
        break;
      }
    }
  }
  if (ok)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
