#include <bits/stdc++.h>
using namespace std;
pair<string, string> v[112345];
long long ord[112345];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    if (s1 < s2) {
      v[i].first = s1;
      v[i].second = s2;
    } else {
      v[i].second = s1;
      v[i].first = s2;
    }
  }
  for (long long i = 0; i < n; i++) {
    long long y;
    cin >> y;
    ord[i] = y - 1;
  }
  string ls = "";
  for (long long i = 0; i < n; i++) {
    if (v[ord[i]].first > ls)
      ls = v[ord[i]].first;
    else if (v[ord[i]].second > ls)
      ls = v[ord[i]].second;
    else {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  return 0;
}
