#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(0);
  int n;
  cin >> n;
  pair<string, int> s[2 * n];
  for (int i = 0; i < n; i++) {
    string x, y;
    cin >> x >> y;
    s[2 * i] = make_pair(x, i);
    s[2 * i + 1] = make_pair(y, i);
  }
  sort(s, s + 2 * n);
  int a[n], b[n];
  memset(a, -1, sizeof(a));
  for (int i = 0; i < 2 * n; i++) {
    if (a[s[i].second] == -1)
      a[s[i].second] = i;
    else
      b[s[i].second] = i;
  }
  int ip[n];
  for (int i = 0; i < n; i++) {
    int tp;
    cin >> tp;
    ip[i] = tp - 1;
  }
  int cv = max(b[ip[n - 1]], a[ip[n - 1]]);
  bool sol = true;
  for (int i = n - 2; i >= 0 && sol; i--) {
    int t = ip[i];
    if (a[t] > b[t]) swap(a[t], b[t]);
    if (b[t] < cv)
      cv = b[t];
    else if (a[t] < cv)
      cv = a[t];
    else
      sol = false;
  }
  if (sol)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
