#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<string, string> > v(n);
  for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
  vector<pair<string, string> > w(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    x--;
    w[i] = v[x];
  }
  vector<string> ret(n);
  ret[0] = min(w[0].first, w[0].second);
  for (int i = 1; i < n; i++) {
    string x = w[i].first, y = w[i].second;
    if (x > y) swap(x, y);
    if (ret[i - 1] < x)
      ret[i] = x;
    else if (ret[i - 1] < y)
      ret[i] = y;
    else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
