#include <bits/stdc++.h>
using namespace std;
int n, seq[100005];
char s[2][55];
string a[100005], b[100005], cur;
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s %s", s[0], s[1]);
    a[i] = s[0];
    b[i] = s[1];
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &seq[i]);
    seq[i]--;
  }
  if (a[seq[0]] < b[seq[0]])
    cur = a[seq[0]];
  else
    cur = b[seq[0]];
  for (int i = 1; i < n; i++) {
    if (cur < a[seq[i]] && cur < b[seq[i]]) {
      if (a[seq[i]] < b[seq[i]])
        cur = a[seq[i]];
      else
        cur = b[seq[i]];
    } else if (cur < a[seq[i]])
      cur = a[seq[i]];
    else if (cur < b[seq[i]])
      cur = b[seq[i]];
    else {
      puts("NO");
      return;
    }
  }
  puts("YES");
}
int main(void) {
  solve();
  return 0;
}
