#include <bits/stdc++.h>
using namespace std;
const int MAXN = int(1e5 + 100);
pair<string, string> names[MAXN];
char buf[2][100];
int p[MAXN];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s%s", buf[0], buf[1]);
    names[i] = make_pair(buf[0], buf[1]);
  }
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
  string prev;
  for (int i = 1; i <= n; ++i) {
    int pos = p[i];
    if (names[pos].first > names[pos].second)
      swap(names[pos].first, names[pos].second);
    if (names[pos].first > prev)
      prev = names[pos].first;
    else if (names[pos].second > prev)
      prev = names[pos].second;
    else {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}
