#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, p;
  string ve[100001], vb[100001], s, mi, ma;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> vb[i] >> ve[i];
  cin >> p;
  s = min(vb[p], ve[p]);
  for (int i = 2; i <= n; i++) {
    cin >> p;
    mi = min(vb[p], ve[p]);
    ma = max(vb[p], ve[p]);
    if (s < mi)
      s = mi;
    else if (s < ma)
      s = ma;
    else {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
