#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 10;
const int MOD = 1e9 + 7;
int n, a[MAX_N];
bool mark[MAX_N];
vector<pair<string, int> > v;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s, s1;
    cin >> s >> s1;
    v.push_back(make_pair(s, i));
    v.push_back(make_pair(s1, i));
  }
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 1; i <= n; i++) {
    pair<string, int> q;
    if (v.size() == 0) {
      cout << "NO";
      return 0;
    }
    q = v[v.size() - 1];
    while (1) {
      if (mark[q.second]) {
        v.pop_back();
        if (v.size() == 0) {
          cout << "NO";
          return 0;
        }
        q = v[v.size() - 1];
        continue;
      }
      if (a[i] == q.second) {
        mark[q.second] = true;
        v.pop_back();
        break;
      } else {
        v.pop_back();
        if (v.size() == 0) {
          cout << "NO";
          return 0;
        }
        q = v[v.size() - 1];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!mark[i]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
