#include <bits/stdc++.h>
struct debugger {
  template <typename T>
  debugger operator,(const T& v) {
    std::cout << v << " ";
    return (*this);
  }
} dbg;
using namespace std;
const int sz = 100000 + 5;
pair<string, int> name[2 * sz];
int main() {
  std::ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = (1); i <= (n); ++i) {
    string s1, s2;
    cin >> s1 >> s2;
    name[2 * i - 1] = make_pair(s1, i);
    name[2 * i] = make_pair(s2, i);
  }
  sort(name + 1, name + 2 * n + 1);
  int cnt = n;
  int prv = 0;
  bool exs = true;
  for (int i = 1; i <= n && exs; ++i) {
    int t;
    cin >> t;
    for (int j = prv + 1; j <= 2 * n; ++j) {
      ;
      if (name[j].second == t) {
        cnt--;
        prv = j;
        break;
      } else if (j == 2 * n) {
        exs = false;
      }
    }
  }
  if (!cnt) {
    cout << "YES\n";
  } else {
    ;
    cout << "NO\n";
  }
}
