#include <bits/stdc++.h>
using namespace std;
string s[100005], t[100005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) cin >> s[i] >> t[i];
  string prev = "";
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    string tmp = "";
    if (s[x] < t[x])
      tmp = s[x];
    else
      tmp = t[x];
    if (tmp > prev) {
      prev = tmp;
      continue;
    }
    if (s[x] < t[x])
      tmp = t[x];
    else
      tmp = s[x];
    if (tmp < prev) {
      printf("NO\n");
      return 0;
    }
    prev = tmp;
  }
  printf("YES\n");
  return 0;
}
