#include <bits/stdc++.h>
using namespace std;
ifstream fin("document.in");
ofstream fout("document.out");
int main() {
  int n, a, b, f = 1;
  cin >> n;
  vector<pair<string, string> > v(n);
  vector<int> x(n);
  for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
  cin >> b;
  b--;
  string t = min(v[b].first, v[b].second);
  for (int i = 1; i < n; i++) {
    cin >> a;
    a--;
    if (v[a].first > v[a].second) {
      string temp = v[a].first;
      v[a].first = v[a].second;
      v[a].second = temp;
    }
    if (v[a].first > t)
      t = v[a].first;
    else if (v[a].second > t)
      t = v[a].second;
    else
      f = 0;
  }
  if (f)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
