#include <bits/stdc++.h>
using namespace std;
const int MAXn = 1000 * 100;
pair<string, string> s[MAXn + 5];
int main() {
  ios_base::sync_with_stdio(false);
  int n, p;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i].first >> s[i].second;
  cin >> p;
  p--;
  string str = min(s[p].first, s[p].second);
  bool flag = true;
  for (int i = 1; i < n; i++) {
    cin >> p;
    p--;
    if (flag) {
      if (s[p].first > str && s[p].second > str)
        str = min(s[p].first, s[p].second);
      else if (s[p].first > str)
        str = s[p].first;
      else if (s[p].second > str)
        str = s[p].second;
      else
        flag = false;
    }
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
