#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T &x) {
  return x.size();
}
const int INF = ~(1 << 31);
const double pi = acos(-1);
const double EPS = 1e-9;
string damn(string a, string b) {
  vector<string> k = {a, b};
  sort(k.begin(), k.end());
  return k[0];
}
string damx(string a, string b) {
  vector<string> k = {a, b};
  sort(k.begin(), k.end());
  return k[1];
}
int main() {
  cin.sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<string, string> > k(n);
  for (int i = (0); i < (n); i++) cin >> k[i].first >> k[i].second;
  string last = "";
  for (int i = (0); i < (n); i++) {
    int at;
    cin >> at;
    at--;
    if (i == 0)
      last = damn(k[at].first, k[at].second);
    else {
      if (damn(last, damn(k[at].first, k[at].second)) == last) {
        last = damn(k[at].first, k[at].second);
      } else if (damn(last, damx(k[at].first, k[at].second)) == last) {
        last = damx(k[at].first, k[at].second);
      } else {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
