#include <bits/stdc++.h>
using namespace std;
string s[100001][2];
int a[100001];
int main() {
  int n;
  int i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s[i][0] >> s[i][1];
    sort(s[i], s[i] + 2);
  }
  for (i = 1; i <= n; i++) cin >> a[i];
  bool flag = true;
  string last = "";
  for (i = 1; i <= n; i++) {
    if (s[a[i]][0] >= last) {
      last = s[a[i]][0];
    } else if (s[a[i]][1] >= last) {
      last = s[a[i]][1];
    } else {
      flag = false;
      break;
    }
  }
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
