#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string f[n + 10], s[n + 10];
  for (int i = 1; i <= n; i++) {
    cin >> f[i];
    cin >> s[i];
  }
  int p[n + 10];
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  string ans[n + 10];
  ans[1] = min(f[p[1]], s[p[1]]);
  for (int i = 2; i <= n; i++) {
    int ind = p[i];
    ans[i] = min(f[ind], s[ind]);
    if (ans[i] < ans[i - 1]) {
      ans[i] = max(f[ind], s[ind]);
      if (ans[i] < ans[i - 1]) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
  return 0;
}
