#include <bits/stdc++.h>
using namespace std;
int N;
string a[100100], b[100100];
string cur = "";
int p[100100];
int main() {
  int i, x;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }
  for (i = 0; i < N; i++) {
    cin >> p[i];
    p[i]--;
  }
  for (i = 0; i < N; i++) {
    x = p[i];
    if (a[x] > b[x]) {
      swap(a[x], b[x]);
    }
    if (cur < a[x]) {
      cur = a[x];
    } else if (cur < b[x]) {
      cur = b[x];
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
