#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> f(n);
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> f[i];
    cin >> s[i];
    if (s[i] < f[i]) swap(s[i], f[i]);
  }
  string ps = "";
  for (int i = 0; i < n; i++) {
    int j;
    cin >> j;
    j--;
    if (f[j] > ps)
      ps = f[j];
    else if (s[j] > ps)
      ps = s[j];
    else {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
