#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string> > s;
int main() {
  int i, n;
  cin >> n;
  for (i = 0; i < n; i++) {
    string cs1, cs2;
    cin >> cs1 >> cs2;
    if (cs1 > cs2) swap(cs1, cs2);
    s.push_back(make_pair(cs1, cs2));
  }
  string prv = "";
  int st = -1;
  for (i = 0; i < n; i++) {
    int c;
    cin >> c;
    c--;
    if (st == -1) {
      st = 1;
      prv = s[c].first;
    } else if (s[c].first > prv) {
      prv = s[c].first;
    } else if (s[c].second > prv) {
      prv = s[c].second;
    } else {
      break;
    }
  }
  if (i == n) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}
