#include <bits/stdc++.h>
using namespace std;
int p[1000005], dp[1000005][2], lenf[1000005], lenl[1000005];
char first[1000005][55], last[1000005][55];
inline int Cmp(char a[], int n, char b[], int m) {
  int i;
  for (i = 1; i <= n && i <= m && a[i] == b[i]; ++i)
    ;
  if (i > n) {
    if (i > m) return 0;
    return 2;
  }
  if (i > m) return 1;
  if (a[i] > b[i]) return 1;
  return 2;
}
int main() {
  int n, i;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> (first[i] + 1) >> (last[i] + 1);
    lenf[i] = strlen(first[i] + 1);
    lenl[i] = strlen(last[i] + 1);
  }
  for (i = 1; i <= n; ++i) cin >> p[i];
  dp[1][0] = dp[1][1] = 1;
  for (i = 2; i <= n; ++i) {
    if (Cmp(first[p[i - 1]], lenf[p[i - 1]], first[p[i]], lenf[p[i]]) != 1)
      dp[i][0] |= dp[i - 1][0];
    if (Cmp(last[p[i - 1]], lenl[p[i - 1]], first[p[i]], lenf[p[i]]) != 1)
      dp[i][0] |= dp[i - 1][1];
    if (Cmp(first[p[i - 1]], lenf[p[i - 1]], last[p[i]], lenl[p[i]]) != 1)
      dp[i][1] |= dp[i - 1][0];
    if (Cmp(last[p[i - 1]], lenl[p[i - 1]], last[p[i]], lenl[p[i]]) != 1)
      dp[i][1] |= dp[i - 1][1];
  }
  if (dp[n][0] | dp[n][1])
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
