#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  vector<pair<string, string> > v;
  for (int i = 0; i < n; i++) {
    string s, s1;
    cin >> s >> s1;
    v.push_back(make_pair(s, s1));
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  string s, s1, s2;
  int k1 = 0;
  for (int i = n - 1; i >= 0; i--) {
    int k = a[i] - 1;
    if (i == n - 1) {
      s = max(v[k].first, v[k].second);
    } else {
      s1 = max(v[k].first, v[k].second);
      s2 = min(v[k].first, v[k].second);
      if (s >= s1) {
        s = s1;
      } else if (s >= s2) {
        s = s2;
      } else {
        k1 = 1;
      }
    }
    if (k1 == 1) {
      break;
    }
  }
  if (k1 == 1) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}
