#include <bits/stdc++.h>
using namespace std;
string arr[2][1000 * 100 + 10];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[0][i] >> arr[1][i];
    if (arr[1][i] < arr[0][i]) swap(arr[1][i], arr[0][i]);
  }
  int k, ans = 1;
  cin >> k;
  string prv = arr[0][k - 1];
  for (int i = 0; i < n - 1; i++) {
    cin >> k;
    if (arr[0][k - 1] > prv)
      prv = arr[0][k - 1];
    else if (arr[1][k - 1] > prv)
      prv = arr[1][k - 1];
    else
      ans = -1;
  }
  if (ans == -1)
    cout << "NO";
  else
    cout << "YES";
  return 0;
}
