#include <bits/stdc++.h>
using namespace std;
priority_queue<string, vector<string>, greater<string> > pq;
string s1, s2;
long long int t[100005];
map<string, long long int> d;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s1 >> s2;
    pq.push(s1);
    pq.push(s2);
    d[s1] = d[s2] = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
  }
  long long int u = 1;
  while (!pq.empty()) {
    string s3 = pq.top();
    if (d[s3] == t[u]) {
      u++;
    }
    pq.pop();
  }
  if (u == n + 1)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
