#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> p[100000];
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;
    p[i].push_back(a);
    p[i].push_back(b);
  }
  int s[100000];
  for (int i = 0; i < n; i++) {
    sort(p[i].begin(), p[i].end());
    cin >> s[i];
    s[i]--;
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j < p[s[i]].size(); j++) {
      bool ok = false;
      for (int k = 0; k < p[s[i + 1]].size(); k++) {
        if (p[s[i]][j].compare(p[s[i + 1]][k]) <= 0) {
          ok = true;
        } else {
          p[s[i + 1]].erase(p[s[i + 1]].begin() + k);
          k--;
        }
      }
      if (ok) goto oki;
    }
    cout << "NO" << endl;
    return 0;
  oki:
    1 == 1;
  }
  cout << "YES" << endl;
  return 0;
}
