#include <bits/stdc++.h>
using namespace std;
const int SZ = 100001;
string f[SZ], s[SZ];
int p[SZ];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> f[i] >> s[i];
  for (int i = 0; i < n; i++) cin >> p[i];
  string pred = "0";
  for (int i = 0; i < n; i++) {
    int k = p[i] - 1;
    string min_s = min(f[k], s[k]);
    string max_s = max(f[k], s[k]);
    if (min_s > pred)
      pred = min_s;
    else if (max_s > pred)
      pred = max_s;
    else {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
