#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  set<pair<string, int> > name, s;
  int n;
  cin >> n;
  string a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    name.insert(make_pair(a, i + 1));
    cin >> a;
    name.insert(make_pair(a, i + 1));
  }
  int temp;
  bool flag = true;
  set<pair<string, int> >::iterator itr1 = name.begin();
  for (int i = 0; i < n; i++) {
    cin >> temp;
    while ((*itr1).second != temp && itr1 != name.end()) itr1++;
  }
  if (itr1 != name.end())
    cout << "YES";
  else
    cout << "NO";
}
