#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  bool lala = 0;
  vector<string> name(n);
  vector<string> last(n);
  vector<long long> ord(n);
  string temp, temp2;
  for (long long i = 0; i < n; i++) {
    cin >> name[i] >> last[i];
  }
  for (long long i = 0; i < n; i++) {
    cin >> ord[i];
  }
  temp = name[ord[0] - 1];
  if (name[ord[0] - 1] > last[ord[0] - 1]) {
    temp = last[ord[0] - 1];
  }
  for (long long i = 1; i < n; i++) {
    if (name[ord[i] - 1] > temp || last[ord[i] - 1] > temp) {
      if (name[ord[i] - 1] > temp) {
        temp2 = name[ord[i] - 1];
      } else {
        temp2 = last[ord[i] - 1];
      }
      if (last[ord[i] - 1] > temp && last[ord[i] - 1] < name[ord[i] - 1]) {
        temp2 = last[ord[i] - 1];
      }
      temp = temp2;
    } else {
      lala = 1;
      break;
    }
  }
  if (lala) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
  }
  return 0;
}
